1

我有一个应用程序可以侦听任何单元格中 DT 中的单元格点击,然后相应地更新绘图。当我在本地运行App() 时,该程序运行良好。但是,当我在闪亮的服务器上部署应用程序时,单击不再触发任何操作。正如我在下面的代码中演示的那样,其他操作侦听器(例如简单的刷新按钮)不存在这种差异。您可以看到刷新按钮条件不存在远程和本地之间的差异input$refreshButton!=0,但使用 length(input$table_cell_clicked)>0触发条件存在差异。

我已经对此错误进行了一些研究,这是我目前所知道的:

"Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience."1)远程部署应用程序时,我在控制台中收到警告。我被告知这与我闪亮服务器中名为 javascript.min.js 和 jquery.min.js 的文件中的设置有关,该文件说c.async="false"我已经在我的服务器上搜索了具有该名称或包含字符串的每个文件async="false",并且将设置更改为sync="true"。但是我没有找到任何具有确切字符串的文件c.async="true"。我可以在浏览器控制台中看到带有这个字符串的文件,它给出了一个相对于 的位置server::port/,但我不知道该文件在我的系统上实际存在的位置,我怀疑它只是由闪亮的服务即时制作的文件。

2)这可能会通过与selectize某些闪亮输入中的功能相关的东西来修复,这可能会导致代码异步执行(?)。我尝试了一些不同的方法,但无法解决问题。

3) Shiny 有一个众所周知的烦恼,通常很难调试。就我而言,如果我能像在本地使用 runApp() 一样看到 server.R 函数的输出,那将非常有帮助。都建议使用对 , 的调用,但是当我将它们添加到下面的代码中时,控制台输出中没有出现任何browser内容。options(shiny.trace = T)我什至尝试使用sink以保存输出到远程服务器上的某个文件,它运行时没有错误,但我在指示的位置没有看到任何文件。如果我至少可以看到这个文件的输出,或者服务器和客户端之间的请求/响应消息,那么调试它会有很长的路要走。

所以这两个问题是:当应用程序被远程部署时,我如何才能看到这些消息/输出?更重要的是,我怎样才能实施修复,这样我在这个项目上的所有辛勤工作(遗憾的是不能透露任何细节)都不会浪费。

我闪亮的应用程序的基本代码如下。

服务器.R:

server <- function(input, output, session) {
options(shiny.trace = T)  
browser()
sink("~/outputfile.txt",append  = T,type = "output",split = T)
  end_date=as.character(as.Date(Sys.Date()-10))
  library(DT)
  library(data.table)
  library(xtable)
  library(zoo)
  library(lattice)
  library(RSQLite)

  output$table = DT::renderDataTable({

    thisTable = head(iris)
  return(thisTable)
  },server = T,options = list(target = 'cell'))



  output$plot1 <- renderPlot({
    cell= as.numeric(input$table_cell_clicked)
    print(cell)

row = as.numeric(input$transtable_row_last_clicked)
print(paste0("last row clicked: ",row))
print(paste0("timestamp: ",Sys.time()))
(cell, file = "/home/plintilhac/cell_file.txt") ## causes error that dumps SND and REC messages to javascript console
   # if (length(input$row_last_clicked)>0){ ##works remotely and locally
   # if (input$refreshButton!=0){   ##works remotely and locally
   if (length(cell)>0){  #works locally, but doesn't work remotely
     plot(0,0,xlim = c(-1,1),ylim = c(-1,1))
    } 
    else{return(plot(0,1,xlim = c(-1,1),ylim = c(-1,1)))}}
  )
  output$text1 <- renderText({ 
    if (input$refreshButton!=0){
      "clicked"
    } 
    else{"unclicked"}
  })
}

用户界面

shinyUI(

  fluidPage(

    fluidRow(plotOutput("plot1",click = "plot_click"),theme = "bootstrap.css"),
    mainPanel(
      DT::dataTableOutput('table'),
      fluidRow(
        actionButton("refreshButton", "refresh")
      )
    )

  ))

编辑:

我能够通过在定义单元变量后立即放置错误的代码行来获得一些输出,从而导致闪亮的服务器将输出转储到 javascript 控制台。目前这是我知道如何捕获任何输出的唯一方法。但是,输出信息量很大,因为它表明 table_cell_clicked 属性根本没有被导出到远程服务器上,而其他属性,例如 row_last_clicked 是。

这是当服务器在本地运行而没有错误行时我得到的输出(注意它包括 table_cell_clicked 作为功能):

SEND
{"config":{"workerId":"","sessionId":"ef292cd0c98baee4afa504aa8330b49e"}}
RECV
{"method":"init","data":{"refreshButton:shiny.action":0,".clientdata_output_plot1_width":873,".clientdata_output_plot1_height":400,".clientdata_output_plot1_hidden":false,".clientdata_output_table_hidden":false,".clientdata_pixelratio":1.100000023841858,".clientdata_url_protocol":"http:",".clientdata_url_hostname":"d2rm01",".clientdata_url_port":"8787",".clientdata_url_pathname":"/p/4944/",".clientdata_url_search":"",".clientdata_url_hash_initial":"",".clientdata_singletons":"",".clientdata_allowDataUriScheme":true}}
SEND
{"errors":[],"values":{"table":{"x":{"filter":"none","container":"<table
class=\"display\">\n  <thead>\n    <tr>\n      <th> </th>\n     
<th>Sepal.Length</th>\n      <th>Sepal.Width</th>\n     
<th>Petal.Length</th>\n      <th>Petal.Width</th>\n     
<th>Species</th>\n    </tr>\n 
</thead>\n</table>","options":{"target":"cell","selectize":true,"columnDefs":[{"className":"dt-right","targets":[1,2,3,4]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"ajax":{"url":"session/ef292cd0c98baee4afa504aa8330b49e/dataobj/table?w=","type":"POST","data":"function(d)
{\nd.search.caseInsensitive = true;\nd.escape = true;\nvar encodeAmp
= function(x) { x.value = x.value.replace(/&/g, \"%26\"); }\nencodeAmp(d.search);\n$.each(d.columns, function(i, v)
{encodeAmp(v.search);});\n}"},"serverSide":true,"processing":true},"selection":{"mode":"multiple","selected":null,"target":"row"}},"evals":["options.ajax.data"],"deps":[{"name":"datatables","version":"1.10.7","src":{"file":"/home/plintilhac/R/x86_64-pc-linux-gnu-library/3.2/DT/htmlwidgets/lib/datatables/js","href":"datatables-1.10.7"},"meta":null,"script":"jquery.dataTables.min.js","stylesheet":null,"head":null,"attachment":null},{"name":"datatables-default","version":"1.10.7","src":{"file":"/home/plintilhac/R/x86_64-pc-linux-gnu-library/3.2/DT/htmlwidgets/lib/datatables/css/default","href":"datatables-default-1.10.7"},"meta":null,"script":[],"stylesheet":["dataTables.extra.css","jquery.dataTables.min.css"],"head":null,"attachment":null}]},"plot1":{"src":"data:image/png;[base64
data]","width":873,"height":400,"coordmap":[{"domain":{"left":-1.08,"right":1.08,"bottom":-1.08,"top":1.08},"range":{"left":58.9093125,"right":842.8269375,"bottom":325.745454545455,"top":57.8909090909091},"log":{"x":null,"y":null},"mapping":{}}]}},"inputMessages":[]}
RECV
{"method":"update","data":{"table_rows_selected":[],"table_rows_current":[],"table_rows_all":[],"table_state":null,"table_search":"","table_cell_clicked":{}}}
SEND {"progress":{"type":"binding","message":{"id":"plot1"}}} SEND
{"errors":[],"values":{"plot1":{"src":"data:image/png;[base64
data]","width":873,"height":400,"coordmap":[{"domain":{"left":-1.08,"right":1.08,"bottom":-1.08,"top":1.08},"range":{"left":58.9093125,"right":842.8269375,"bottom":325.745454545455,"top":57.8909090909091},"log":{"x":null,"y":null},"mapping":{}}]}},"inputMessages":[]}
RECV
{"method":"update","data":{"table_rows_current":[1,2,3,4,5,6],"table_rows_all":[1,2,3,4,5,6]}}
RECV {"method":"update","data":{"plot_click":null}} RECV
{"method":"update","data":{"table_cell_clicked":{"row":1,"col":2,"value":3.5},"table_rows_selected":[1],"table_row_last_clicked":1}}
SEND {"progress":{"type":"binding","message":{"id":"plot1"}}} SEND
{"errors":[],"values":{"plot1":{"src":"data:image/png;[base64
data]","width":873,"height":400,"coordmap":[{"domain":{"left":-1.08,"right":1.08,"bottom":-1.08,"top":1.08},"range":{"left":58.9093125,"right":842.8269375,"bottom":325.745454545455,"top":57.8909090909091},"log":{"x":null,"y":null},"mapping":{}}]}},"inputMessages":[]}
RECV {"method":"update","data":{"table_rows_selected":[]}}

虽然这是使用错误行远程运行时的输出(注意未收到 table_cell_clicked):

Loading required package: DBI
    SEND {"errors":[],"values":{"table":{"x":{"container":"<table class=\"display\">\n  <thead>\n    <tr>\n      <th> </th>\n      <th>Sepal.Length</th>\n      <th>Sepal.Width</th>\n      <th>Petal.Length</th>\n      <th>Petal.Width</th>\n      <th>Species</th>\n    </tr>\n  </thead>\n</table>","options":{"target":"cell","selectize":true,"columnDefs":[{"className":"dt-right","targets":[1,2,3,4]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"ajax":{"url":"session/07190712bb533d7cf1929522b19e436a/dataobj/table?w=","type":"POST","data":"function(d) {\nd.search.caseInsensitive = true;\nd.escape = true;\n}"},"serverSide":true,"processing":true},"callback":null,"filter":"none","selection":"multiple"},"evals":["options.ajax.data"],"deps":[{"name":"datatables","version":"1.10.7","src":{"file":"/usr/local/lib/R/site-library/DT/htmlwidgets/lib/datatables/js","href":"datatables-1.10.7"},"meta":null,"script":"jquery.dataTables.min.js","stylesheet":null,"head":null,"attachment":null},{"name":"datatables-default","version":"1.10.7","src":{"file":"/usr/local/lib/R/site-library/DT/htmlwidgets/lib/datatables/css/default","href":"datatables-default-1.10.7"},"meta":null,"script":[],"stylesheet":["dataTables.extra.css","jquery.dataTables.min.css"],"head":null,"attachment":null}]},"plot1":{"src":"data:image/png;[base64 data]","width":1745,"height":400,"coordmap":[{"domain":{"left":-1.08,"right":1.08,"bottom":-1.08,"top":1.08},"range":{"left":58.9062532569046,"right":1714.82850442939,"bottom":325.745454545455,"top":57.8909090909091},"log":{"x":null,"y":null},"mapping":{}}]}},"inputMessages":[]}
    RECV {"method":"update","data":{"table_rows_selected":[],"table_rows_current":[],"table_rows_all":[],"table_state":null,"table_search":""}}
    RECV {"method":"update","data":{"table_rows_current":["1","2","3","4","5","6"],"table_rows_all":["1","2","3","4","5","6"]}}
    RECV {"method":"update","data":{"table_rows_selected":["3"],"table_row_last_clicked":"3"}}
    RECV {"method":"update","data":{".clientdata_output_plot1_width":463}}
    SEND {"progress":{"type":"binding","message":{"id":"plot1"}}}
    SEND {"errors":[],"values":{"plot1":{"src":"data:image/png;[base64 data]","width":463,"height":400,"coordmap":[{"domain":{"left":-1.08,"right":1.08,"bottom":-1.08,"top":1.08},"range":{"left":58.9256188605108,"right":432.81858546169,"bottom":325.745454545455,"top":57.8909090909091},"log":{"x":null,"y":null},"mapping":{}}]}},"inputMessages":[]}
    RECV {"method":"update","data":{"plot_click":null}}
    SEND {"config":{"workerId":"","sessionId":"7b20c500ee810e198324a75b6512a353"}}
    RECV {"method":"init","data":{"refreshButton:shiny.action":0,"ss-net-opt-websocket":true,"ss-net-opt-xdr-streaming":true,"ss-net-opt-xhr-streaming":true,"ss-net-opt-iframe-eventsource":true,"ss-net-opt-iframe-htmlfile":true,"ss-net-opt-xdr-polling":true,"ss-net-opt-xhr-polling":true,"ss-net-opt-iframe-xhr-polling":true,"ss-net-opt-jsonp-polling":true,".clientdata_output_plot1_width":463,".clientdata_output_plot1_height":400,".clientdata_output_plot1_hidden":false,".clientdata_output_table_hidden":false,".clientdata_pixelratio":1.100000023841858,".clientdata_url_protocol":"http:",".clientdata_url_hostname":"d2rm01",".clientdata_url_port":"3838",".clientdata_url_pathname":"/testFunnel/",".clientdata_url_search":"",".clientdata_url_hash_initial":"",".clientdata_singletons":"",".clientdata_allowDataUriScheme":true}}
    Error in source(file, ..., keep.source = TRUE, encoding = checkEncoding(file)) : 
      /srv/shiny-server/testFunnel/server.R:38:10: unexpected ','
    37:     #print(paste0("timestamp: ",Sys.time()))
    38:     (cell,
4

0 回答 0