I have an data table output in my Shiny app and want to pre-select the first cell of it. I created a very simple example below with one column and the target cell as selection option.
library(DT)
shinyApp(
ui = fluidPage(
fluidRow(
h1('Data table'),
DT::dataTableOutput('tab')
)
),
server = function(input, output, session) {
col1 = c('Car', 'Truck', 'Bike')
df = data.frame(col1)
output$tab = DT::renderDataTable(
df, server = FALSE,
selection = list(mode = 'single',target="cell"),
rownames= FALSE
)
}
)
How can I (in this case) pre-select the first cell (Car)?
I found this: How to pre-select cells in Shiny DT datatables
In this post I read that I have to use a matrix as selection criteria, but I am not able to get it right i my example.