JDG*_*JDG 8 json r shiny shiny-server dt
我有一个 Shiny Server 应用程序,用户可以在其中编辑数据表,然后相应地更新一些反应性摘要统计信息。我在一个相当慢的框架上托管这个应用程序,这就是为什么我想使用客户端处理进行 DT 渲染,即server = F传递给DT::renderDataTable. 让我分解我的问题的要点:
代码在server = T通过时完全可操作。
当传递 时server = F,当用户在 DT 中编辑单元格时,浏览器会抛出以下错误消息:
DataTables 警告:table id=DataTables_Table_5 - JSON 响应无效。有关此错误的更多信息,请参阅 http://datatables.net/tn/1
有趣的是,当这个错误窗口被关闭时,依赖摘要统计信息会根据编辑正确更新,并且 Shiny 应用程序继续。因此,除错误外,一切正常。我应该注意到,我访问了错误中提到的网站,但没有变得更聪明。
下面可重现的例子:
library(shiny)
library(DT)
dt = data.frame(V1 = c(1,2), V2 = c(3,4))
server <- function(input, output, session) {
val = reactiveValues(mat = data.table(dt))
output$testDT = renderDataTable({
DT::datatable(val$mat, editable = TRUE)
}, server = FALSE)
proxy = dataTableProxy('testDT')
observeEvent(input$testDT_cell_edit, {
info = input$testDT_cell_edit
str(info)
i = info$row
j = info$col
v = info$val
if (j == 1){
val$mat$V1[i] = DT::coerceValue(v, val$mat$V1[i])
replaceData(proxy, val$mat, rownames = FALSE)
}
})
}
ui <- fluidPage(
dataTableOutput('testDT')
)
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
谢谢!