I'm using Shiny (0.12.0) with DT (0.0.65) for row-selections in this Shiny datatable. I want to pre-select the first 5 rows. I have tried:
callback
JS in datatable. However, that is not reflecting in the input$x1_rows_selected
variable. Only the background/highlight changes because of CSS..click()
in either rowCallback
in the options list or in callback
. This does not work either when loading the page. However, it works (updates input$x1_rows_selected
) when I run the same code through the console / browser dev tool.callback
JS:
output$x1 = DT::renderDataTable({
datatable(cars,
rows = $("#x1 tbody tr");
$(rows).slice(0,5).each(function() {
$(this).click();
});
)
})
This feature has been added to DT (>= 0.1.3). Examples:
library(shiny)
if (packageVersion('DT') < '0.1.3') devtools::install_github('rstudio/DT')
library(DT)
shinyApp(
ui = fluidPage(
fluidRow(
h1('Client-side processing'),
DT::dataTableOutput('x1'),
h1('Server-side processing'),
DT::dataTableOutput('x2')
)
),
server = function(input, output, session) {
output$x1 = DT::renderDataTable(
iris, server = FALSE,
selection = list(mode = 'multiple', selected = c(1, 3, 8, 12))
)
output$x2 = DT::renderDataTable(
iris, server = TRUE,
selection = list(mode = 'multiple', selected = rownames(iris)[c(1, 3, 8, 12)])
)
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With