我们正在尝试重新创建示例:https://demo.shinyapps.io/029-row-selection/ ,使用DT包渲染数据框而不是闪亮的包.DT :: Datatable也有'回调'选项,但是当使用与demo中相同的javascriptcode时它似乎不起作用.
我们目前的代码:
shinyServer(function(input, output) {
output$tbl <- DT::renderDataTable(
DT::datatable(mtcars,options = list(pageLength = 10,
callback = JS("function(table) {
table.on('click.dt', 'tr', function() {
$(this).toggleClass('selected');
Shiny.onInputChange('rows',
table.rows('.selected').indexes ().toArray());
});
}")
))
)
output$rows_out <- renderText({
paste(c('You selected these rows on the page:', rows),
collapse = ' ')
})
})
Run Code Online (Sandbox Code Playgroud)
有谁知道如何实现这一目标?
非常感谢托马斯
PS:在下面的示例中,我们找到了如何为数据表中的列着色: renderDataTable选择包含值> 10的所有单元格并突出显示
好的,我找到了解决方案.这是有效的,清理输出需要更多的工作,但我认为我们完成了90%.马克斯
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(dataTableOutput('foo'),textOutput('rows_out')),
server = function(input, output) {
output$foo = renderDataTable({
datatable(iris,
callback = JS(
"table.on('click.dt', 'tr', function() {
$(this).toggleClass('selected');
Shiny.onInputChange('rows',
table.rows('.selected').data().toArray());
});")
)
})
output$rows_out =renderText({
paste(c('You selected these rows on the page:', input$rows),
collapse = ' ')
})
}
)
Run Code Online (Sandbox Code Playgroud)