Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R shiny uncheck checkboxGroup with actionbutton

I have checkboxGroup with selected items, and actionButton. I need on actionButton click uncheck checkBoxGroup.

          wellPanel(
             checkboxGroupInput(datename, "Select dates:", some_dates,
                                selected = outlier_dates_to_select),
             actionButton("buttonname", "Uncheck all")
        ) 

Any suggestions, how I can manage that?

Thank you a lot!

like image 254
Marta Avatar asked Feb 20 '14 10:02

Marta


1 Answers

You have to use actionButton like this for example :

In ui.R :

shinyUI(pageWithSidebar(
  headerPanel(title=""),
  sidebarPanel(
    checkboxGroupInput("Test1", "Test1", choices=c("1","2","3"), selected="1"),
    checkboxGroupInput("Test2", "Test2", choices=c("1","2","3"), selected="2"),
    actionButton("Uncheck", label="Uncheck")
  ),
  mainPanel()
))

And in server.R :

shinyServer(function(input, output, session) {
  observe({
   if (input$Uncheck > 0) {
      updateCheckboxGroupInput(session=session, inputId="Test1", choices=c("1","2","3"), selected=NULL)
      updateCheckboxGroupInput(session=session, inputId="Test2", choices=c("1","2","3"), selected=NULL)
   }
 })
})

You have to repeat choices in updateCheckboxGroupInput to make it work.

like image 154
Victorp Avatar answered Oct 30 '22 17:10

Victorp