单击的单元格在本地工作但不在远程闪亮服务器上工作--DT

时间:2016-02-17 16:16:14

标签: ajax r asynchronous shiny dt

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

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

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

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

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

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

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

server.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"}
  })
}

ui.R

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,

0 个答案:

没有答案