Create a select input that scales to very large choice sets
Source:R/select_inputs.R
viz_select_input.RdA drop-in replacement for shiny::selectInput() built on
shinyWidgets::virtualSelectInput(). The underlying virtual-select
library renders only the visible slice of the choice list, so a column with
tens of thousands of unique values stays responsive and readable instead of
producing an unusable wall of options.
Usage
viz_select_input(
inputId,
label,
choices,
selected = NULL,
multiple = FALSE,
search = NULL,
width = "100%",
...
)Arguments
- inputId
The
inputslot that will be used to access the value.- label
Display label for the control, or
NULLfor no label.- choices
A vector or named list of values to select from, in the same form accepted by
shiny::selectInput().- selected
The initially selected value(s). Defaults to the first choice for single selects and nothing for multiple selects.
- multiple
Logical, whether multiple values can be selected.
- search
Logical, whether to show a search box. Defaults to
NULL, which enables the search box once there are more than 10 choices.- width
The width of the input, e.g.
"100%"or"400px".- ...
Further arguments passed to
shinyWidgets::virtualSelectInput(), including any rawvirtual-selectproperty such asoptionsCountorzIndex.
Details
Defaults are chosen so this behaves like shiny::selectInput():
when selected is not supplied and multiple = FALSE, the first choice is
selected. An empty-string choice (the "no selection" convention used
throughout this package) is relabelled "(none)" so it is visible in the
dropdown, while its value remains "".
Examples
if (FALSE) { # interactive()
library(VizModules)
viz_select_input("gene", "Gene", choices = c("", paste0("GENE", 1:1000)))
}