In this example, I'm removing rows of the datatable using checkboxGroupInput, but I'd prefer to have a column of radio buttons in the table itself to select which rows to remove. I've tried reading the documentation and examples that others have posted, but I can't decipher any of it. How can I solve this?
library(shiny)
library(DT)
mtcars[["cars"]] <- row.names(mtcars)
example_mtcars <- head(mtcars, n = 5)
ui <- fluidPage(
checkboxGroupInput("mtcars_update", "Select Cars to Remove", choices = example_mtcars$cars),
shiny::dataTableOutput("mtcars_dt")
)
server <- function(input, output, session) {
output$mtcars_dt <- shiny::renderDataTable({
if (length(input$mtcars_update) == 0) {
example_mtcars
} else {
example_mtcars |>
dplyr::filter(cars != input$mtcars_update)
}
})
}
shinyApp(ui, server)
Created on 2024-03-16 with reprex v2.1.0
