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:
- Changing the class of row using
callback
JS in datatable. However, that is not reflecting in theinput$x1_rows_selected
variable. Only the background/highlight changes because of CSS. - Using
.click()
in eitherrowCallback
in the options list or incallback
. This does not work either when loading the page. However, it works (updatesinput$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: