Reputation: 18500
My dropdown box is an optional filter. If one or more items are selected, then a filtering is performed. If nothing is selected -- no filtering.
I would like to communicate that behaviour. By default, the input box is empty. Is there a way to show some custom string instead? Also, I would like to include an option, that, when selected, clears the selection.
I tried the following, after reading this:
require(shiny)
ui <- fluidPage(
shiny::selectizeInput(
inputId="letters",
label="Restrict to Letters:",
choices=letters,
selected=NULL,
multiple = TRUE,
options=list(
allowEmptyOption=TRUE,
showEmptyOptionInDropdown=TRUE,
emptyOptionLabel="(all letters)"
)
)
)
server <- function(input, output){}
shinyApp(ui=ui, server=server)
}
but no "empty option" is displayed. What am I doing wrong?
Upvotes: 0
Views: 169
Reputation: 1112
In order to be able to clear your selections, you will have to update the selectize input and activate it with an action button:
library(shiny)
ui <- fluidPage(
shiny::selectizeInput(
inputId="letters",
label="Restrict to Letters:",
choices=letters,
selected=NULL,
multiple = TRUE,
options=list(
allowEmptyOption=TRUE,
showEmptyOptionInDropdown=TRUE,
emptyOptionLabel="(all letters)"
)
),
actionButton("update","Clear")
)
server <- function(input, output,session){
observeEvent(input$update,{
updateSelectizeInput(inputId = "letters",choices = "",session)
})
}
shinyApp(ui=ui, server=server)
Upvotes: 1