M455y
M455y

Reputation: 322

Show dropdown menu only when start typing in R Shinyapp

With Shiny when you use SelectizeInput with multiple = TRUE:

  1. a dropdown menu with all the element appears as soon as you are in that box.
  2. Then, when you start typing, the result in the dropdown menu are filtered depending on what you type.

When the list is very long, sometimes the point 1 is pointless. Is it possible to see the dropdown only when you start typing (only from point 2)?

Reproducible example:

ui <- fluidPage(
    selectizeInput(
        inputId = "TEST", label = NULL, choices = c("aa","ab","ac","dd","de","zzz"),
        multiple = TRUE)
)

server <- function(input, output, session) {          
    }

shinyApp(ui, server)

Upvotes: 1

Views: 367

Answers (1)

A. Suliman
A. Suliman

Reputation: 13125

selectizeInput has an options argument, which is a list of parameters to initialize the selectize input. One of these options is openOnFocus which is

Show the dropdown immediately when the control receives focus.

Turning off openOnFocus solves the issue.

 selectizeInput(
    inputId = "TEST", label = NULL, choices = c("aa","ab","ac","dd","de","zzz"),
    multiple = TRUE,
    options = list(openOnFocus = FALSE,
                   #If the user write aa then delete it all, the complete list will show up again, 
                   #use maxOptions to solve this issue
                   maxOptions = 3))

See the full list here selectize / selectize.js.

Upvotes: 2

Related Questions