【发布时间】:2018-09-21 13:57:09
【问题描述】:
我正在开发一个闪亮的应用程序,用户可以在其中选择大数据集中的多个列来创建该数据集的子集。我使用包 DT 在闪亮的应用程序中很好地呈现表格。
我之前使用了 DT 包的 0.2 版,其中以下代码正在运行:
library("DT")
library("shiny")
ui <- fluidPage(
DT::dataTableOutput('table1'),
DT::dataTableOutput("table2")
)
server <- function(input, output) {
output$table1 <- DT::renderDataTable({
datatable(mtcars, extensions = 'Select', selection = 'none', options = list(ordering = FALSE, searching = FALSE, pageLength = 25, select = list(style = 'os', items = 'column')),
callback = JS(
"table.on( 'click.dt', 'tbody td', function (e) {",
"var type = table.select.items();",
"var idx = table[type + 's']({selected: true}).indexes().toArray();",
"var DT_id = table.table().container().parentNode.id;",
"Shiny.onInputChange(DT_id + '_columns_selected', idx);",
"})"
))
})
output$table2 <- DT::renderDataTable({
subset_table <- mtcars[,input$table1_columns_selected]
datatable(subset_table)
})
}
shinyApp(ui = ui, server = server)
不幸的是,这段代码不再工作了(我现在在 0.4 版本下)。 input$table1_columns_selected 不会呈现所选列的索引。
根据这个https://rstudio.github.io/DT/shiny.html,现在有一个选择多行的功能,但我不知道如何对列做同样的事情。
有什么想法吗? 非常感谢您的帮助!
【问题讨论】: