I am trying to delete the rows from a dataframe when they have been selected in the datatable and someone presses the \"Delete Rows\" switch. input$click_rows_selected gives the
The following code should help you toward a solution.
Please note that the practice to have nested observe
should be in general avoided.
I've added updateCheckboxGroupInput
as I thought it made sense in the context of the example.
library(shiny)
values <- reactiveValues(df = iris)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
checkboxGroupInput('inputId', label=NULL, choices = colnames(df), selected = NULL,
inline = FALSE, width = NULL, choiceNames = NULL, choiceValues = NULL),
actionButton("deleterows", "push to delete")
),
mainPanel(tableOutput("contents")
)
))
server <- function(input,output,session){
observeEvent(input$deleterows,{
cols <- setdiff(colnames(values$df), input$inputId)
values$df <- values$df[c(cols)]
updateCheckboxGroupInput(session, 'inputId', label = NULL, choices = colnames(values$df),
selected = NULL, inline = FALSE, choiceNames = NULL,
choiceValues = NULL)
})
output$contents <- renderTable({
values$df
})
}
shinyApp(ui,server)