| Title: | Animated Glass-Style Tabs and Multi-Select Filter for 'Shiny' |
|---|---|
| Description: | Tools for creating animated glassmorphism-style tab navigation and select filter widgets in 'Shiny' applications. Provides a tab navigation component with a sliding glass halo animation, a searchable multi-select dropdown, and a single-select dropdown — all with multiple colour themes and server-side update helpers. Tabs support icons, numeric badges, disable/enable toggling, runtime append/remove, reactive rendering via 'renderGlassTabs()', URL bookmarking, and compact mode for dashboard card layouts. 'glassTabCondition()' generates 'conditionalPanel()' condition strings without needing to recall the internal input key pattern. 'glasstabs_news()' displays the release notes from the R console. Built-in example apps can be launched with 'runGlassExample()'. All widgets are compatible with standard 'Shiny' layouts and 'bs4Dash' dashboards. |
| Authors: | George Arthur [aut, cre] |
| Maintainer: | George Arthur <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.2 |
| Built: | 2026-06-01 21:07:19 UTC |
| Source: | https://github.com/prigasg/glasstabs |
appendGlassTab() adds a new glassTabPanel() to an existing
glassTabsUI() at runtime. removeGlassTab() removes a tab by value.
If the removed tab was active, the first remaining tab is activated.
appendGlassTab(session, id, tab, select = FALSE) removeGlassTab(session, id, value)appendGlassTab(session, id, tab, select = FALSE) removeGlassTab(session, id, value)
session |
Shiny session object. |
id |
Module id matching the |
tab |
A |
select |
Logical. If |
value |
Value of the tab to remove (for |
Called for its side effect; returns NULL invisibly.
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("home", "Home", p("Home content"), selected = TRUE) ), actionButton("add", "Add tab"), actionButton("remove", "Remove tab") ) server <- function(input, output, session) { observeEvent(input$add, { appendGlassTab(session, "tabs", glassTabPanel("new", "New Tab", p("Dynamic content")), select = TRUE ) }) observeEvent(input$remove, { removeGlassTab(session, "tabs", "new") }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("home", "Home", p("Home content"), selected = TRUE) ), actionButton("add", "Add tab"), actionButton("remove", "Remove tab") ) server <- function(input, output, session) { observeEvent(input$add, { appendGlassTab(session, "tabs", glassTabPanel("new", "New Tab", p("Dynamic content")), select = TRUE ) }) observeEvent(input$remove, { removeGlassTab(session, "tabs", "new") }) } shinyApp(ui, server) }
disableGlassTab() grays out a tab and prevents the user from clicking it
without removing it from the navigation bar. enableGlassTab() reverses
this. Unlike hideGlassTab(), a disabled tab remains visible.
disableGlassTab(session, id, value) enableGlassTab(session, id, value)disableGlassTab(session, id, value) enableGlassTab(session, id, value)
session |
Shiny session object. |
id |
Module id matching the |
value |
Value of the tab to disable or enable. |
Called for its side effect; returns NULL invisibly.
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")), glassTabPanel("locked", "Locked", p("Locked content")) ), checkboxInput("unlocked", "Unlock tab", FALSE) ) server <- function(input, output, session) { # Start with "locked" tab disabled observe({ if (input$unlocked) enableGlassTab(session, "tabs", "locked") else disableGlassTab(session, "tabs", "locked") }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")), glassTabPanel("locked", "Locked", p("Locked content")) ), checkboxInput("unlocked", "Unlock tab", FALSE) ) server <- function(input, output, session) { # Start with "locked" tab disabled observe({ if (input$unlocked) enableGlassTab(session, "tabs", "locked") else disableGlassTab(session, "tabs", "locked") }) } shinyApp(ui, server) }
All color arguments accept any valid CSS color string (hex, rgb(),
rgba(), named colors). Unset fields inherit from the mode base preset.
glass_select_theme( mode = c("dark", "light"), bg_color = NULL, border_color = NULL, text_color = NULL, accent_color = NULL, label_color = NULL )glass_select_theme( mode = c("dark", "light"), bg_color = NULL, border_color = NULL, text_color = NULL, accent_color = NULL, label_color = NULL )
mode |
Base preset. One of |
bg_color |
Background of the trigger button and dropdown panel. |
border_color |
Border color of the trigger and dropdown. |
text_color |
Main text color for options and the trigger label. |
accent_color |
Highlight color for checkmarks, badges, and selected states. Also used for the focus ring. |
label_color |
Widget label color. Defaults to |
A named list of class "glass_select_theme" for passing to the
theme argument of glassMultiSelect() or glassSelect().
# Teal accent on a dark base teal_theme <- glass_select_theme( mode = "dark", accent_color = "#2dd4bf", bg_color = "rgba(9, 20, 42, 0.97)" ) # Light mode with a custom purple accent purple_light <- glass_select_theme( mode = "light", accent_color = "#7c3aed", border_color = "rgba(124, 58, 237, 0.35)" ) if (interactive()) { library(shiny) choices <- c(Revenue = "rev", Orders = "ord", Returns = "ret") ui <- fluidPage( useGlassTabs(), glassMultiSelect("metric", choices, theme = teal_theme), glassSelect("region", c(All = "all", North = "n", South = "s"), theme = purple_light) ) server <- function(input, output, session) {} shinyApp(ui, server) }# Teal accent on a dark base teal_theme <- glass_select_theme( mode = "dark", accent_color = "#2dd4bf", bg_color = "rgba(9, 20, 42, 0.97)" ) # Light mode with a custom purple accent purple_light <- glass_select_theme( mode = "light", accent_color = "#7c3aed", border_color = "rgba(124, 58, 237, 0.35)" ) if (interactive()) { library(shiny) choices <- c(Revenue = "rev", Orders = "ord", Returns = "ret") ui <- fluidPage( useGlassTabs(), glassMultiSelect("metric", choices, theme = teal_theme), glassSelect("region", c(All = "all", North = "n", South = "s"), theme = purple_light) ) server <- function(input, output, session) {} shinyApp(ui, server) }
All arguments accept any valid CSS color string (hex, rgb(), rgba(),
named colors). Pass only the fields you want to override — unset fields
fall back to the dark-mode defaults.
glass_tab_theme( tab_text = NULL, tab_active_text = NULL, halo_bg = NULL, halo_border = NULL, content_bg = NULL, content_border = NULL, card_bg = NULL, card_text = NULL )glass_tab_theme( tab_text = NULL, tab_active_text = NULL, halo_bg = NULL, halo_border = NULL, content_bg = NULL, content_border = NULL, card_bg = NULL, card_text = NULL )
tab_text |
Inactive tab text color. |
tab_active_text |
Active tab text color (and headings inside cards). |
halo_bg |
Background fill of the animated glass halo. |
halo_border |
Border color of the glass halo. |
content_bg |
Tab content area background. |
content_border |
Tab content area border. |
card_bg |
Inner |
card_text |
Inner |
A named list of class "glass_tab_theme" for passing to
the theme argument of glassTabsUI().
Light mode color accessibility: When building a light-mode theme,
ensure tab_text is dark enough to read on a white background (e.g. at
least "#374151") and tab_active_text provides strong contrast (e.g.
"#1d4ed8" or darker). Light-grey or near-white values that look fine on
dark backgrounds become invisible on light ones.
# Amber / warm accent on a dark base amber <- glass_tab_theme( halo_bg = "rgba(251, 191, 36, 0.15)", halo_border = "rgba(251, 191, 36, 0.40)", tab_active_text = "#fef3c7" ) if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "demo", glassTabPanel("a", "Alpha", selected = TRUE, p("Alpha content")), glassTabPanel("b", "Beta", p("Beta content")), theme = amber ) ) server <- function(input, output, session) {} shinyApp(ui, server) }# Amber / warm accent on a dark base amber <- glass_tab_theme( halo_bg = "rgba(251, 191, 36, 0.15)", halo_border = "rgba(251, 191, 36, 0.40)", tab_active_text = "#fef3c7" ) if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "demo", glassTabPanel("a", "Alpha", selected = TRUE, p("Alpha content")), glassTabPanel("b", "Beta", p("Beta content")), theme = amber ) ) server <- function(input, output, session) {} shinyApp(ui, server) }
Renders a <div> that the JS engine will populate with colored tag pills
whenever the corresponding glassMultiSelect() selection changes.
glassFilterTags(inputId, class = NULL)glassFilterTags(inputId, class = NULL)
inputId |
The |
class |
Additional CSS classes for the container. |
An htmltools tag.
A stylized multi-select Shiny input with optional search, style switching,
select-all behavior, and programmatic updates via updateGlassMultiSelect().
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", hues = NULL, dark_selector = NULL )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", hues = NULL, dark_selector = NULL )
inputId |
Shiny input id. |
choices |
Named or unnamed character vector of choices. |
selected |
Initially selected values. Defaults to all choices when
|
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 |
show_style_switcher |
Show the Check / Box / Fill switcher row inside
the dropdown? Default |
show_select_all |
Show the "Select all" row? Default |
show_clear_all |
Show the "Clear all" footer link? Default |
theme |
Color theme. One of |
hues |
Optional named integer vector of HSL hue angles (0 to 360) for
the |
dark_selector |
Optional CSS selector that signals dark mode (e.g.
|
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.
An htmltools::tagList containing the trigger button, dropdown
panel, and scoped <style> block.
fruits <- c(Apple = "apple", Banana = "banana", Cherry = "cherry") # Minimal glassMultiSelect("f", fruits) # Lock style, hide extra controls glassMultiSelect( "f", fruits, check_style = "check-only", show_style_switcher = FALSE, show_select_all = FALSE, show_clear_all = FALSE ) # Light theme glassMultiSelect("f", fruits, theme = "light")fruits <- c(Apple = "apple", Banana = "banana", Cherry = "cherry") # Minimal glassMultiSelect("f", fruits) # Lock style, hide extra controls glassMultiSelect( "f", fruits, check_style = "check-only", show_style_switcher = FALSE, show_select_all = FALSE, show_clear_all = FALSE ) # Light theme glassMultiSelect("f", fruits, theme = "light")
Convenience helper for extracting a multi-select widget's value and style
from Shiny's input object without using modules.
glassMultiSelectValue(input, inputId)glassMultiSelectValue(input, inputId)
input |
Shiny |
inputId |
Input id used in |
A named list with two reactives:
selectedReactive character vector of selected values
styleReactive string for the active style
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassMultiSelect("cats", c(A = "a", B = "b", C = "c")) ) server <- function(input, output, session) { ms <- glassMultiSelectValue(input, "cats") observe({ message("Selected: ", paste(ms$selected(), collapse = ", ")) message("Style: ", ms$style()) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassMultiSelect("cats", c(A = "a", B = "b", C = "c")) ) server <- function(input, output, session) { ms <- glassMultiSelectValue(input, "cats") observe({ message("Selected: ", paste(ms$selected(), collapse = ", ")) message("Style: ", ms$style()) }) } shinyApp(ui, server) }
A stylized single-select Shiny input with optional search, clear control,
selection-marker styling, and programmatic updates via updateGlassSelect().
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" )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" )
inputId |
Shiny input id. |
choices |
Named or unnamed character vector of choices. |
selected |
Initially selected value. Defaults to |
label |
Optional field label shown above the widget. |
placeholder |
Trigger label when nothing is selected. |
searchable |
Logical. Show search input inside dropdown? Default
|
clearable |
Logical. Show clear control for removing the current
selection? Default |
include_all |
Logical. Prepend an explicit "All" option. Default
|
all_choice_label |
Label used for the explicit "All" option. |
all_choice_value |
Value used for the explicit "All" option. |
check_style |
One of |
theme |
Color theme. One of |
The widget registers one Shiny input:
input$<inputId> : selected value as a length-1 character string,
or NULL when nothing is selected
An htmltools::tagList containing the single-select trigger,
dropdown panel, and scoped <style> block.
fruits <- c(Apple = "apple", Banana = "banana", Cherry = "cherry") glassSelect("fruit", fruits) glassSelect( "fruit", fruits, selected = "banana", clearable = TRUE ) glassSelect( "fruit", fruits, include_all = TRUE, all_choice_label = "All fruits", all_choice_value = "__all__" ) glassSelect( "fruit", fruits, check_style = "filled" )fruits <- c(Apple = "apple", Banana = "banana", Cherry = "cherry") glassSelect("fruit", fruits) glassSelect( "fruit", fruits, selected = "banana", clearable = TRUE ) glassSelect( "fruit", fruits, include_all = TRUE, all_choice_label = "All fruits", all_choice_value = "__all__" ) glassSelect( "fruit", fruits, check_style = "filled" )
Convenience helper for extracting a single-select widget's value from Shiny's
input object without using modules.
glassSelectValue(input, inputId)glassSelectValue(input, inputId)
input |
Shiny |
inputId |
Input id used in |
A reactive expression returning the current selected value as a
character scalar, or NULL when nothing is selected.
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassSelect("fruit", c(Apple = "apple", Banana = "banana")) ) server <- function(input, output, session) { fruit <- glassSelectValue(input, "fruit") observe({ print(fruit()) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassSelect("fruit", c(Apple = "apple", Banana = "banana")) ) server <- function(input, output, session) { fruit <- glassSelectValue(input, "fruit") observe({ print(fruit()) }) } shinyApp(ui, server) }
Returns a JavaScript condition string that evaluates to TRUE when the
specified glasstabs widget has a given active tab. Pass the result directly
to the condition argument of shiny::conditionalPanel().
glassTabCondition(id, value)glassTabCondition(id, value)
id |
The |
value |
The tab value string (the |
A single character string for use in shiny::conditionalPanel().
# Basic usage in a plain Shiny app: if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "main", glassTabPanel("overview", "Overview", selected = TRUE, p("Always visible.")), glassTabPanel("details", "Details", p("Detail pane.")) ), conditionalPanel( condition = glassTabCondition("main", "details"), wellPanel("This panel only shows on the Details tab.") ) ) server <- function(input, output, session) {} shinyApp(ui, server) } # Inside a module — use ns() for the id: # UI: glassTabCondition(ns("tabs"), "details") # This produces: "input['mymod-tabs-active_tab'] === 'details'"# Basic usage in a plain Shiny app: if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "main", glassTabPanel("overview", "Overview", selected = TRUE, p("Always visible.")), glassTabPanel("details", "Details", p("Detail pane.")) ), conditionalPanel( condition = glassTabCondition("main", "details"), wellPanel("This panel only shows on the Details tab.") ) ) server <- function(input, output, session) {} shinyApp(ui, server) } # Inside a module — use ns() for the id: # UI: glassTabCondition(ns("tabs"), "details") # This produces: "input['mymod-tabs-active_tab'] === 'details'"
Used as child arguments inside glassTabsUI(). Each call defines one tab
button and its associated content pane.
glassTabPanel(value, label, ..., icon = NULL, selected = FALSE)glassTabPanel(value, label, ..., icon = NULL, selected = FALSE)
value |
A unique string identifier for this tab (e.g. |
label |
The text shown on the tab button. |
... |
UI elements for the pane content. |
icon |
Optional icon shown to the left of the tab label. Accepts
any htmltools-compatible tag, e.g. |
selected |
Logical. Whether this tab starts selected. Only the first
|
A list of class "glassTabPanel" consumed by glassTabsUI().
# Plain text label glassTabPanel("overview", "Overview", shiny::h3("Welcome"), shiny::p("This is the overview tab.") ) # With a Shiny icon glassTabPanel("data", "Data", icon = shiny::icon("table"), shiny::p("Data content here.") )# Plain text label glassTabPanel("overview", "Overview", shiny::h3("Welcome"), shiny::p("This is the overview tab.") ) # With a Shiny icon glassTabPanel("data", "Data", icon = shiny::icon("table"), shiny::p("Data content here.") )
Prints the package NEWS to the R console. Useful for quickly checking what changed between versions without leaving your R session.
glasstabs_news()glasstabs_news()
Called for its side effect; returns NULL invisibly.
glasstabs_news()glasstabs_news()
A drop-in replacement for shiny::uiOutput() that pairs with
renderGlassTabs(). It creates a placeholder <div> that Shiny fills
with a fully reactive glassTabsUI() when the server-side render function
runs. The JavaScript engine is automatically (re-)initialised after each
render.
glassTabsOutput(outputId, ...)glassTabsOutput(outputId, ...)
outputId |
The output id used in the paired |
... |
Additional arguments forwarded to |
A shiny.tag suitable for use in a Shiny UI.
if (interactive()) { library(shiny) tab_data <- list( list(value = "a", label = "Alpha"), list(value = "b", label = "Beta"), list(value = "c", label = "Gamma") ) ui <- fluidPage( useGlassTabs(), selectInput("n", "Show tabs", choices = 2:3, selected = 2), glassTabsOutput("dynamic_tabs") ) server <- function(input, output, session) { output$dynamic_tabs <- renderGlassTabs({ panels <- lapply( head(tab_data, as.integer(input$n)), function(t) glassTabPanel(t$value, t$label, p(t$label)) ) do.call(glassTabsUI, c(list("dyn"), panels)) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) tab_data <- list( list(value = "a", label = "Alpha"), list(value = "b", label = "Beta"), list(value = "c", label = "Gamma") ) ui <- fluidPage( useGlassTabs(), selectInput("n", "Show tabs", choices = 2:3, selected = 2), glassTabsOutput("dynamic_tabs") ) server <- function(input, output, session) { output$dynamic_tabs <- renderGlassTabs({ panels <- lapply( head(tab_data, as.integer(input$n)), function(t) glassTabPanel(t$value, t$label, p(t$label)) ) do.call(glassTabsUI, c(list("dyn"), panels)) }) } shinyApp(ui, server) }
Tracks the active tab and exposes it as a reactive value. Optionally integrates with Shiny's bookmarking system so the active tab is preserved in bookmarked URLs.
glassTabsServer(id, bookmark = TRUE)glassTabsServer(id, bookmark = TRUE)
id |
Module id matching the |
bookmark |
Logical. When |
glassTabsServer() follows the same calling convention as all Shiny module
server functions: pass the bare module id, not a namespaced one.
Inside a parent module, pair it with glassTabsUI(ns("tabs"), ...) in the
UI, and call glassTabsServer("tabs") (without ns()) in the server.
A reactive expression returning the active tab value.
# --- Standalone app --- if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")) ) ) server <- function(input, output, session) { active <- glassTabsServer("tabs") observe(print(active())) } shinyApp(ui, server) } # --- Bookmarking --- if (interactive()) { library(shiny) ui <- function(request) { fluidPage( useGlassTabs(), bookmarkButton(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")) ) ) } server <- function(input, output, session) { active <- glassTabsServer("tabs", bookmark = TRUE) } shinyApp(ui, server, enableBookmarking = "url") } # --- Inside a Shiny module --- # UI side: use ns() to namespace the widget id my_module_ui <- function(id) { ns <- shiny::NS(id) shiny::tagList( useGlassTabs(), glassTabsUI( ns("tabs"), # <-- ns() wraps the id here glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")) ) ) } # Server side: pass the bare id — NOT ns("tabs") my_module_server <- function(id) { shiny::moduleServer(id, function(input, output, session) { active <- glassTabsServer("tabs") # <-- bare id, no ns() shiny::observe(print(active())) }) }# --- Standalone app --- if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")) ) ) server <- function(input, output, session) { active <- glassTabsServer("tabs") observe(print(active())) } shinyApp(ui, server) } # --- Bookmarking --- if (interactive()) { library(shiny) ui <- function(request) { fluidPage( useGlassTabs(), bookmarkButton(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")) ) ) } server <- function(input, output, session) { active <- glassTabsServer("tabs", bookmark = TRUE) } shinyApp(ui, server, enableBookmarking = "url") } # --- Inside a Shiny module --- # UI side: use ns() to namespace the widget id my_module_ui <- function(id) { ns <- shiny::NS(id) shiny::tagList( useGlassTabs(), glassTabsUI( ns("tabs"), # <-- ns() wraps the id here glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")) ) ) } # Server side: pass the bare id — NOT ns("tabs") my_module_server <- function(id) { shiny::moduleServer(id, function(input, output, session) { active <- glassTabsServer("tabs") # <-- bare id, no ns() shiny::observe(print(active())) }) }
Animated glass-style tab navigation UI
glassTabsUI( id, ..., selected = NULL, wrap = TRUE, compact = FALSE, extra_ui = NULL, theme = NULL, dark_selector = NULL )glassTabsUI( id, ..., selected = NULL, wrap = TRUE, compact = FALSE, extra_ui = NULL, theme = NULL, dark_selector = NULL )
id |
Module namespace id. |
... |
One or more |
selected |
Value of the initially selected tab. |
wrap |
Logical. When |
compact |
Logical. When |
extra_ui |
Optional additional UI placed to the right of the tab bar. |
theme |
One of |
dark_selector |
Optional CSS selector for a parent element that signals
dark mode (e.g. |
An htmltools::tagList ready to use in a Shiny UI.
Server-side render function that pairs with glassTabsOutput(). The
expression should return a glassTabsUI() call. After each render the
glasstabs JavaScript engine is automatically reinitialised so animations and
event handlers are correctly attached to the new DOM nodes.
renderGlassTabs(expr, env = parent.frame(), quoted = FALSE)renderGlassTabs(expr, env = parent.frame(), quoted = FALSE)
expr |
An expression that returns a |
env |
The environment in which to evaluate |
quoted |
Logical. Whether |
A render function suitable for assigning to an output slot.
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), radioButtons("theme", "Theme", c("dark", "light"), inline = TRUE), glassTabsOutput("tabs_out") ) server <- function(input, output, session) { output$tabs_out <- renderGlassTabs({ glassTabsUI( "themed", glassTabPanel("x", "X", selected = TRUE, p("X content")), glassTabPanel("y", "Y", p("Y content")), theme = input$theme ) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), radioButtons("theme", "Theme", c("dark", "light"), inline = TRUE), glassTabsOutput("tabs_out") ) server <- function(input, output, session) { output$tabs_out <- renderGlassTabs({ glassTabsUI( "themed", glassTabPanel("x", "X", selected = TRUE, p("X content")), glassTabPanel("y", "Y", p("Y content")), theme = input$theme ) }) } shinyApp(ui, server) }
Launches one of the example Shiny apps that ship with the package. A list of available examples is printed when called with no arguments. Example apps are launched only in interactive sessions.
runGlassExample(example = NULL, ...)runGlassExample(example = NULL, ...)
example |
Name of the example to run. One of |
... |
Additional arguments passed to |
Called for its side-effect (launches a Shiny app).
# List available examples runGlassExample() # Run an example interactively if (interactive()) { runGlassExample("smoke-test") }# List available examples runGlassExample() # Run an example interactively if (interactive()) { runGlassExample("smoke-test") }
showGlassTab() makes a hidden tab visible again.
hideGlassTab() hides a tab from the navigation bar. If the hidden tab is
currently active, the first remaining visible tab is activated automatically.
showGlassTab(session, id, value) hideGlassTab(session, id, value)showGlassTab(session, id, value) hideGlassTab(session, id, value)
session |
Shiny session object. |
id |
Module id matching the |
value |
Value of the tab to show or hide. |
Called for its side effect; returns NULL invisibly.
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")), glassTabPanel("admin", "Admin", p("Admin only")) ), checkboxInput("is_admin", "Admin mode", FALSE) ) server <- function(input, output, session) { observeEvent(input$is_admin, { if (input$is_admin) showGlassTab(session, "tabs", "admin") else hideGlassTab(session, "tabs", "admin") }, ignoreInit = FALSE) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")), glassTabPanel("admin", "Admin", p("Admin only")) ), checkboxInput("is_admin", "Admin mode", FALSE) ) server <- function(input, output, session) { observeEvent(input$is_admin, { if (input$is_admin) showGlassTab(session, "tabs", "admin") else hideGlassTab(session, "tabs", "admin") }, ignoreInit = FALSE) } shinyApp(ui, server) }
Update the available choices and/or current selection of an existing
glassMultiSelect() input.
updateGlassMultiSelect( session, inputId, choices = NULL, selected = NULL, check_style = NULL )updateGlassMultiSelect( session, inputId, choices = NULL, selected = NULL, check_style = NULL )
session |
Shiny session. |
inputId |
Input id of the widget. |
choices |
New choices, or |
selected |
New selected values, or |
check_style |
Optional new style string. One of |
This function now follows Shiny-style update semantics more closely:
choices = NULL leaves choices unchanged
selected = NULL leaves selection unchanged
selected = character(0) clears the selection
When choices is supplied and selected is not, the browser side
keeps the intersection of the current selection and the new set of choices.
No return value. Called for its side effect of updating the client-side widget.
Update the available choices, current selection, and/or selection-marker
style of an existing glassSelect() input.
updateGlassSelect( session, inputId, choices = NULL, selected = NULL, check_style = NULL )updateGlassSelect( session, inputId, choices = NULL, selected = NULL, check_style = NULL )
session |
Shiny session. |
inputId |
Input id of the widget. |
choices |
New choices, or |
selected |
New selected value, or |
check_style |
Optional new style string. One of |
This function follows Shiny-style update semantics:
choices = NULL leaves choices unchanged
selected = NULL leaves selection unchanged
selected = character(0) clears the selection
check_style = NULL leaves the current style unchanged
When choices is supplied and selected is not, the browser side
keeps the current selection if it is still present in the new choices.
No return value. Called for its side effect of updating the client-side widget.
Adds or updates a small numeric badge on a tab button — useful for
surfacing counts such as unread items, pending rows, or notification
totals. Set count to 0 or NA to hide the badge.
updateGlassTabBadge(session, id, value, count)updateGlassTabBadge(session, id, value, count)
session |
Shiny session object. |
id |
Module id matching the |
value |
Value of the tab to update. |
count |
Integer count to display. Values above 99 are shown as
|
Called for its side effect; returns NULL invisibly.
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("inbox", "Inbox", p("Messages here"), selected = TRUE), glassTabPanel("sent", "Sent", p("Sent items")), glassTabPanel("drafts", "Drafts", p("Draft items")) ), actionButton("refresh", "Refresh counts") ) server <- function(input, output, session) { observeEvent(input$refresh, { updateGlassTabBadge(session, "tabs", "inbox", count = sample(1:20, 1)) updateGlassTabBadge(session, "tabs", "drafts", count = sample(0:5, 1)) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("inbox", "Inbox", p("Messages here"), selected = TRUE), glassTabPanel("sent", "Sent", p("Sent items")), glassTabPanel("drafts", "Drafts", p("Draft items")) ), actionButton("refresh", "Refresh counts") ) server <- function(input, output, session) { observeEvent(input$refresh, { updateGlassTabBadge(session, "tabs", "inbox", count = sample(1:20, 1)) updateGlassTabBadge(session, "tabs", "drafts", count = sample(0:5, 1)) }) } shinyApp(ui, server) }
Server-side equivalent of Shiny's updateTabsetPanel(). Sends a
message to the browser to animate the tab switch just as if the user had
clicked the tab button.
updateGlassTabsUI(session, id, selected)updateGlassTabsUI(session, id, selected)
session |
Shiny session object. |
id |
Module id matching the |
selected |
Value of the tab to activate. |
Called for its side effect; returns NULL invisibly.
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")) ), actionButton("go", "Go to B") ) server <- function(input, output, session) { observeEvent(input$go, { updateGlassTabsUI(session, "tabs", selected = "b") }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI( "tabs", glassTabPanel("a", "A", p("Tab A"), selected = TRUE), glassTabPanel("b", "B", p("Tab B")) ), actionButton("go", "Go to B") ) server <- function(input, output, session) { observeEvent(input$go, { updateGlassTabsUI(session, "tabs", selected = "b") }) } shinyApp(ui, server) }
Call this once in your UI — either inside fluidPage(), bs4DashPage(),
or any other Shiny page wrapper. It injects the required CSS and JS as
proper htmltools dependencies so they are deduplicated automatically.
useGlassTabs()useGlassTabs()
An htmltools::htmlDependency object (invisible to the user,
consumed by Shiny's renderer).
if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI("demo", glassTabPanel("A", "Tab A", p("Content A")), glassTabPanel("B", "Tab B", p("Content B")) ) ) server <- function(input, output, session) {} shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( useGlassTabs(), glassTabsUI("demo", glassTabPanel("A", "Tab A", p("Content A")), glassTabPanel("B", "Tab B", p("Content B")) ) ) server <- function(input, output, session) {} shinyApp(ui, server) }