service_navigation_server: Auto-wire service navigation links to tabset panels

View source: R/service_navigation.R

service_navigation_serverR Documentation

Auto-wire service navigation links to tabset panels

Description

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.

Usage

service_navigation_server(session, tabset_id, link_to_panel)

Arguments

session

The Shiny session object

tabset_id

The id of the shiny::tabsetPanel() or bslib::navset_hidden() to switch

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 service_navigation(), so "Page-Two" and "page_two" both refer to the same link. Panel values are used exactly as given.

Value

NULL, called for side effects

See Also

Other Govstyle navigation: backlink_Input(), navigate_to(), service_navigation(), update_page_title(), update_service_navigation()

Examples

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)

shinyGovstyle documentation built on Oct. 16, 2026, 1:07 a.m.