After finding this solution, I successfully implemented a column of checkboxes in a datatable using Shiny. However, I encountered an issue where the row heights could not be adjusted with DT::formatStyle()
when the checkbox column was present. Below is a simplified example:
library(shiny)
library(DT)
runApp(
list(ui = fluidPage(
column(width = 6,
dataTableOutput("cars_table")),
column(width = 6,
dataTableOutput("cars_table_check"))),
server = function(input, output, session) {
shinyInput <- function(FUN, id, num, ...) {
inputs <- character(num)
for (i in seq_len(num)) {
inputs[i] <- as.character(FUN(paste0(id, i), label = NULL, ...))
}
inputs
}
output$cars_table <- renderDataTable({
formatStyle(datatable(
mtcars,
selection = 'none', escape = F),
0, target = "row", lineHeight = "50%")
})
output$cars_table_check <- renderDataTable({
formatStyle(datatable(
cbind(Pick = shinyInput(checkboxInput, "srows_", nrow(mtcars), value = NULL, width = 1), mtcars),
options = list(drawCallback= JS('function(settings) {Shiny.bindAll(this.api().table().node());}')),
selection = 'none', escape = F),
0, target = "row", lineHeight = "50%")
})
})
)
Here is how it looks: