View source: R/service_navigation.R
| service_navigation_server | R Documentation |
Sets up one observer per nav link that switches the corresponding tab
panel when the link is clicked. Eliminates the per-link
observeEvent() boilerplate that multi-page apps would otherwise need.
Call once in your server function, after service_navigation() has been
added to the UI. The active nav highlight and (when
auto_page_title = TRUE) the browser tab title are already handled
client-side, so no additional wiring is needed.
service_navigation_server(session, tabset_id, link_to_panel)
session |
The Shiny session object |
tabset_id |
The |
link_to_panel |
A character vector mapping nav link inputIds to
tab panel values. Pass a named vector when inputIds differ from
panel values (names = inputIds, values = panel values). Pass an
unnamed vector as shorthand for the 1:1 case — each element is
used as both the nav inputId and the panel value. InputIds are cleaned
up the same way as in |
NULL, called for side effects
Other Govstyle navigation:
backlink_Input(),
navigate_to(),
service_navigation(),
update_page_title(),
update_service_navigation()
ui <- shinyGovstyle::gov_page(
shinyGovstyle::service_navigation(
c(Summary = "sn_summary", Detail = "sn_detail")
),
bslib::navset_hidden(
id = "tabs",
bslib::nav_panel("summary", "Summary content"),
bslib::nav_panel("detailed_data", "Detail content")
)
)
server <- function(input, output, session) {
# Nav inputIds differ from panel values
shinyGovstyle::service_navigation_server(
session,
tabset_id = "tabs",
link_to_panel = c(
sn_summary = "summary",
sn_detail = "detailed_data"
)
)
# Or, when inputIds match panel values exactly:
# shinyGovstyle::service_navigation_server(
# session,
# tabset_id = "tabs",
# link_to_panel = c("summary", "detailed_data")
# )
}
if (interactive()) shiny::shinyApp(ui = ui, server = server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.