I am following this example of how to get elements from a row that is clicked on. This works fine except it does not highlight the selected row. Here is the code:
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})
}
))