问题
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