5

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!

Marta
  • 3,493
  • 6
  • 28
  • 43

1 Answers1

11

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.

Victorp
  • 13,636
  • 2
  • 51
  • 55
  • Thank you for the answer, but I need to do that with checkboxGroupInput, not with checkboxInput. Because I have to dynamically change checkboxgroupinput list and selected items list. – Marta Feb 20 '14 at 11:15
  • 1
    Sorry i misread your question, i edited my answer, does it better? – Victorp Feb 20 '14 at 12:36
  • Thank you a lot! And for first answer too! Owing to your idea on updateCheckbox, I found function updateCheckboxGroupInput. – Marta Feb 20 '14 at 12:53