Reputation: 219
I my shiny app I have few pickerInput elements. As a default nothing is selected.
pickerInput(
inputId = "pickerInput1",
label = NULL,
choices = c("Yes", "No"),
options = list(
`actions-box` = TRUE,
size = 12,
`selected-text-format` = "count > 3"
),
multiple = TRUE
)
The problem is that I have no idea how I can clear all of them (go to default value) after click on a special button. Unfortunately I propobly don't know how to use updatePickerInput. I tried:
observeEvent(input$Clear_FilterButton, {
updatePickerInput(session, "pickerInput1", selected = NULL)
})
but it doesn't work :( Any ideas what I am doing wrong?
Upvotes: 2
Views: 2636
Reputation: 2864
If you are using the pickerInput
from shinyWidgets
, setting actions-box
to TRUE
should build Select All & Deselect All buttons by default. You don't need updatePickerInput
. Click on your pickerInput
to see these buttons.
Please refer to the documentation for additional details:
https://github.com/dreamRs/shinyWidgets
Update following up your comment:
Your comment made the question more clear. You can simply use selected = ""
instead of selected = NULL
. Here is a working example:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
pickerInput(
inputId = "pickerInput1",
label = NULL,
choices = c("Yes", "No"),
options = list(
`actions-box` = TRUE,
size = 12
),
multiple = TRUE
),
actionButton(
inputId = "Clear_FilterButton",
label = "Clear"
)
)
server <- function(session, input, output) {
observeEvent(input$Clear_FilterButton, {
updatePickerInput(
session,
"pickerInput1",
selected = ""
)
})
}
shinyApp(ui = ui, server = server)
Upvotes: 6