rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.37k stars 1.87k forks source link

Preserve search in selectizeInput #3347

Open tylerlittlefield opened 3 years ago

tylerlittlefield commented 3 years ago

I have a dropdown with thousands of choices that relies on selectizeInput because of the server side processing feature. A common use case is to start typing and narrow in on a couple of choices, then select them all. However, this is challenging because once you select a single choice, the choices are no longer filtered to what was searched.

Can we add an option to preserve the search? There is a similar issue on the selectize.js repo with a plugin here: https://github.com/selectize/selectize.js/issues/878

mathidachuk commented 3 years ago

I found a solution posted on Stackoverflow that seems to do the trick: https://stackoverflow.com/questions/62882671/retain-selection-criteria-in-selectize

Basically you attach the plugin dependency on selectize input creation:

addPreserveSearch <- function(x) {
  preserve_search <- htmlDependency("preserve_search", "1.0","location_of_your_script_folder",
                                script = "preserve_search.js")

  attachDependencies(x, c(htmlDependencies(x), list(preserve_search)))
}