R shiny uncheck checkboxGroup with actionbutton

回眸只為那壹抹淺笑 提交于 2021-02-07 18:16:58

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/21904869/r-shiny-uncheck-checkboxgroup-with-actionbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!