A stylized single-select Shiny input with optional search, clear control,
selection-marker styling, and programmatic updates via updateGlassSelect().
Usage
glassSelect(
inputId,
choices,
selected = NULL,
label = NULL,
placeholder = "Select an option",
searchable = TRUE,
clearable = FALSE,
include_all = FALSE,
all_choice_label = "All categories",
all_choice_value = "__all__",
check_style = c("checkbox", "check-only", "filled"),
theme = "dark",
shape = c("rounded", "square"),
width = NULL,
disabled = FALSE,
disabled_choices = NULL,
server = FALSE,
server_limit = 50L,
server_min_chars = 0L,
no_matches_text = "No matches",
tongue = TRUE,
label_bold = TRUE,
label_size = "14px",
search_focus_ring = FALSE,
overflow_tooltip = c("auto", "never"),
search_threshold = 15L,
dark_selector = NULL
)Arguments
- inputId
Shiny input id.
- choices
Named or unnamed character vector of choices, or a named list for grouped choices (selectInput()-style). A one-element named list such as
list(Group = "x")is treated as a flat, ungrouped choice, mirroringshiny::selectInput().- selected
Initially selected value. Defaults to
NULL.- label
Optional field label shown above the widget.
- placeholder
Trigger label when nothing is selected.
- searchable
Search visibility. Use
TRUE(default) to always show search,FALSEto hide it, or"auto"to show it only when the choice count reachessearch_threshold.- clearable
Logical. Show clear control for removing the current selection? Default
FALSE.- include_all
Logical. Prepend an explicit "All" option. Default
FALSE.- all_choice_label
Label used for the explicit "All" option.
- all_choice_value
Value used for the explicit "All" option.
- check_style
One of
"checkbox"(default),"check-only", or"filled".- theme
Color theme. One of
"dark"(default),"light","auto", or aglass_select_theme()object."auto"uses the light preset by default and switches to the dark preset when an ancestor carriesdata-bs-theme="dark".- shape
Corner style for the trigger and dropdown. One of
"rounded"(default) for the signature glass look, or"square"for crisp, selectize-style corners so the widget sits neatly alongside native ShinyselectizeInput()controls.- width
Optional widget width passed to
shiny::validateCssUnit(), e.g.100%or240px. WhenNULL(default) the trigger uses a stable compact width of160px. Explicit widths continue to be capped by the container.- disabled
Logical. When
TRUEthe whole widget is greyed out and non-interactive. DefaultFALSE.- disabled_choices
Optional character vector of choice values to render as disabled (non-selectable) rows. Default
NULL.- server
Logical. If
TRUE, render only an initial slice of choices and useglassSelectServer()to search the full choice set from the Shiny server. DefaultFALSE.- server_limit
Maximum number of choices rendered initially. Search results are bounded separately by the
limitargument of the*Server()helper. Default50. Explicitly selected values that fall outside the initial slice are still rendered as extra rows so they stay visible and checked.- server_min_chars
Minimum search characters required before server-side matching filters choices. Default
0.- no_matches_text
Text shown when a search matches no choices. Default
"No matches".- tongue
Logical. When
TRUE(default), the dropdown attaches to the trigger and uses the signature tongue unfurl/retract animation. Set toFALSEfor a detached panel with a short fade that sits more naturally beside native Shiny inputs.- label_bold
Logical. Use a semibold field label, matching native Shiny inputs, when
TRUE(default). Set toFALSEfor regular-weight label text.- label_size
CSS size for the field label. The default,
"14px", keeps the title visually distinct from the dropdown options.- search_focus_ring
Logical. When
TRUE, focusing the dropdown search field adds the accent-colored outline. The default,FALSE, uses a quieter background and border change without the outer ring.- overflow_tooltip
Tooltip behavior for trigger text that is visually truncated with an ellipsis.
"auto"(default) shows the complete text on pointer hover or keyboard focus only when truncation is detected;"never"disables it. On touch devices, opening the dropdown remains the primary way to inspect the full, wrapped option text.- search_threshold
Choice count at which
searchable = "auto"shows the search field. Default15.- dark_selector
Optional CSS selector that signals dark mode (e.g.
"body.dark-mode"for bs4Dash). When provided, emits an extra scoped<style>block that reverts colors to the dark-mode defaults whenever that selector is active.
Value
An htmltools::tagList containing the single-select trigger,
dropdown panel, and scoped <style> block.
Details
The widget registers one Shiny input:
input$<inputId>: selected value as a length-1 character string, orNULLwhen nothing is selected
See also
Other glass select widgets:
glassMultiSelect(),
glassMultiSelectServer(),
glassMultiSelectValue(),
glassSelectServer(),
glassSelectValue(),
updateGlassMultiSelect(),
updateGlassSelect()
Examples
fruits <- c(Apple = "apple", Banana = "banana", Cherry = "cherry")
fruit_select <- glassSelect("fruit", fruits)
selected_fruit <- glassSelect(
"fruit",
fruits,
selected = "banana",
clearable = TRUE
)
all_fruits <- glassSelect(
"fruit",
fruits,
include_all = TRUE,
all_choice_label = "All fruits",
all_choice_value = "__all__"
)
filled_fruit <- glassSelect(
"fruit",
fruits,
check_style = "filled"
)