Skip to contents

A stylized multi-select Shiny input with optional search, style switching, select-all behavior, and programmatic updates via updateGlassMultiSelect().

Usage

glassMultiSelect(
  inputId,
  choices,
  selected = NULL,
  label = NULL,
  placeholder = "Filter by Category",
  all_label = "All categories",
  check_style = c("checkbox", "check-only", "filled"),
  show_style_switcher = TRUE,
  show_select_all = TRUE,
  show_clear_all = TRUE,
  theme = "dark",
  shape = c("rounded", "square"),
  width = NULL,
  disabled = FALSE,
  disabled_choices = NULL,
  hues = NULL,
  dark_selector = NULL,
  server = FALSE,
  server_limit = 50L,
  server_min_chars = 0L,
  searchable = TRUE,
  search_threshold = 15L,
  selection_display = c("auto", "count", "summary", "labels"),
  selection_max_items = 2L,
  dropdown_max_height = "260px",
  no_matches_text = "No matches"
)

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, mirroring shiny::selectInput().

selected

Initially selected values. Defaults to all choices when NULL.

label

Optional field label shown above the widget.

placeholder

Trigger label when nothing is selected.

all_label

Label shown when all choices are selected.

check_style

One of "checkbox" (default), "check-only", or "filled".

show_style_switcher

Show the Check / Box / Fill switcher row inside the dropdown? Default TRUE.

show_select_all

Show the "Select all" row? Default TRUE.

show_clear_all

Show the "Clear all" footer link? Default TRUE.

theme

Color theme. One of "dark" (default), "light", "auto", or a glass_select_theme() object. "auto" uses the light preset by default and switches to the dark preset when an ancestor carries data-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 Shiny selectizeInput() controls.

width

Optional widget width passed to shiny::validateCssUnit(), e.g. 100% or 240px. When NULL (default) the trigger uses a stable compact width of 160px. Explicit widths continue to be capped by the container.

disabled

Logical. When TRUE the whole widget is greyed out and non-interactive. Default FALSE.

disabled_choices

Optional character vector of choice values to render as disabled (non-selectable) rows. Default NULL.

hues

Optional named integer vector of HSL hue angles (0 to 360) for the "filled" style. Auto-assigned if NULL.

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.

server

Logical. If TRUE, render only an initial slice of choices and use glassMultiSelectServer() to search the full choice set from the Shiny server. Default FALSE.

server_limit

Maximum number of choices rendered initially and returned for each server-side search. Default 50. 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.

searchable

Search visibility. Use TRUE (default) to always show search, FALSE to hide it, or "auto" to show it only when the choice count reaches search_threshold.

search_threshold

Choice count at which searchable = "auto" shows the search field. Default 15.

selection_display

How partial selections are summarized in the trigger: "auto" (the existing behavior), "count", "summary", or "labels".

selection_max_items

Number of labels shown by selection_display = "summary" before the remaining count is shown.

dropdown_max_height

Maximum height of the scrolling option area as a CSS unit, such as "18rem" or "320px". The default is "260px".

no_matches_text

Text shown when a search matches no choices. Default "No matches". This argument is last so that existing positional calls keep working.

Value

An htmltools::tagList containing the trigger button, dropdown panel, and scoped <style> block.

Details

The widget registers two Shiny inputs:

  • input$<inputId> : character vector of selected values

  • input$<inputId>_style : active style string ("checkbox", "check-only", or "filled")

By default, when selected = NULL, all choices are initially selected. This preserves the existing package behavior.

Examples

fruits <- c(Apple = "apple", Banana = "banana", Cherry = "cherry")

# Minimal
fruit_filter <- glassMultiSelect("f", fruits)

# Lock style, hide extra controls
locked_filter <- glassMultiSelect(
  "f",
  fruits,
  check_style = "check-only",
  show_style_switcher = FALSE,
  show_select_all = FALSE,
  show_clear_all = FALSE
)

# Light theme
light_filter <- glassMultiSelect("f", fruits, theme = "light")