M.Yosh
M.Yosh

Reputation: 47

pickerInput Not Clearing All Choices

I'm having an issue with clearing out choices selected by the user under pickerInput of the shinyWidget package. Here's the code below:

library(shinyWidgets)
library(shiny)

shinyApp(
  ui = basicPage(
    actionButton("show", "Click me!")
  ),

  server = function(input, output){

    observeEvent(input$show, {
      showModal(
        modalDialog(
          h2("Select Years", align = "center"),
          pickerInput(inputId = "Yearz", label = NULL, 
                      choices = c(2012:2017), options = list(
                        `selected-text-format` = "count > 3", `actions-box` = TRUE), 
                      multiple = TRUE, width = "100%")
        )
      )
    })

    observeEvent(input$Yearz, {
      print(input$Yearz)
    }
    )
  }
)

I notice that when the last option selected is deselected, whether through the "Deselect All" button or through manual means, that the last option still remains under input$Yearz. Is there a way to make values inside input$Yearz all null?

Upvotes: 1

Views: 1217

Answers (1)

Victorp
Victorp

Reputation: 13856

When no choices are selected in pickerInput, value in server is NULL and observeEvent ignore NULL, so do :

observeEvent(input$Yearz, {
  print(input$Yearz)
}, ignoreNULL = FALSE)

Upvotes: 3

Related Questions