| glassTabsServer | R Documentation |
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)
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.
Other glass tabs:
appendGlassTab(),
disableGlassTab(),
glassTabCondition(),
glassTabPanel(),
glassTabsOutput(),
glassTabsUI(),
renderGlassTabs(),
showGlassTab(),
updateGlassTabBadge(),
updateGlassTabsUI()
# --- 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()))
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.