我正在关注如何从单击的行中获取元素的示例。这工作正常,只是它没有突出显示选定的行。这是代码:
library(DT)
library(shiny)
runApp(shinyApp(
ui = fluidPage(DT::dataTableOutput('tab'), verbatimTextOutput('row')),
server = function(input, output) {
output$tab = DT::renderDataTable({
datatable(iris, selection = 'single',
callback = JS("table.on('click.dt', 'tr',
function() {
$(this).toggleClass('selected');
Shiny.onInputChange('row', table.rows('.selected').data().toArray());
});")
)
})
output$row = renderText({input$row})
}
))