【发布时间】:2015-01-07 09:08:25
【问题描述】:
我正在尝试创建我的第一个 Shiny R 应用程序,它做了两件事:
- 显示用户上传的 CSV 文件
- 统计用户选择的行数
为了实现这些功能,我需要结合file upload和row selection这两个例子,其中涉及将renderTable切换为renderDataTable。但是,我只能使用renderDataTable 显示数据,但无法将callback 和options 等参数传递给它。
这里是server.R代码
shinyServer(function(input, output) {
output$contents <- renderDataTable({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
subset(read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote), select=input$show_vars)
})
})
如果我在这种情况下(如下)更改上述功能,我会收到以下错误server.R:9:5: unexpected 'if'。我认为这与构建一个反应式文件上传应用程序有关,我找不到好的例子......谁能给我一些建议?谢谢!
shinyServer(function(input, output) {
output$contents <- renderDataTable(
inFile <- input$file1
if (is.null(inFile))
return(NULL)
subset(read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote), select=input$show_vars),
options = list(pageLength = 10),
callback = "function(table) {
table.on('click.dt', 'tr', function() {
$(this).toggleClass('selected');
Shiny.onInputChange('rows',
table.rows('.selected').indexes().toArray());
});
}"
)
})
【问题讨论】:
标签: r shiny rstudio shiny-server