I want to implement checkboxes into my shiny app; however, I'm facing two problems:
- After I reorder columns, any checks on the datatable disappear (e.g., try to order table by
mpg) - After I remove column, any checks on the datatable disappear (e.g., unchecking boxes from
Columns to show:)
Here's my dummy example (it's a modified version of code from this SO answer):
library(shiny)
TABLE = mtcars
TABLE$id = 1:nrow(mtcars)
APP <- list()
APP$ui <- pageWithSidebar(
headerPanel(NULL),
sidebarPanel(
checkboxGroupInput("show_vars", "Columns to show:",
names(TABLE), selected = names(TABLE))
),
mainPanel(
dataTableOutput("resultTABLE")
)
)
APP$server <- function(input, output, session) {
output$resultTABLE = renderDataTable({
addCheckboxButtons <- paste0('<input type="checkbox" name="row',
TABLE$id, '" value="', TABLE$id, '">',"")
cbind(Pick = addCheckboxButtons, TABLE[, input$show_vars, drop = FALSE])
}, escape = FALSE)
}
runApp(APP)
APP works, but for the full implementation I need to solve problems 1 and 2.