| navigate_to | R Documentation |
Switches the visible tab panel and updates the active service navigation link in a single call. Use this for programmatic navigation — next / back buttons, modal links, footer shortcuts to a main page — where the user has not clicked a nav link directly.
When service_navigation() is used with auto_page_title = TRUE (the
default), the browser tab title is updated automatically too, because
update_service_navigation() triggers the title sync via the
JavaScript binding.
By default the nav link inputId is also used as the target tab panel
value. When they differ — for example when nav inputIds carry a prefix
like sn_ to disambiguate from panel values — pass panel explicitly.
navigate_to(session, tabset_id, inputId, panel = inputId)
session |
The Shiny session object |
tabset_id |
The |
inputId |
The nav link inputId to set as the active item in the
service navigation. It is cleaned up the same way as in
|
panel |
The |
NULL, called for side effects
Other Govstyle navigation:
backlink_Input(),
service_navigation(),
service_navigation_server(),
update_page_title(),
update_service_navigation()
# Next / back buttons that cross page boundaries — inputId and panel
# value match, so a single id is enough.
ui <- shinyGovstyle::gov_page(
shinyGovstyle::service_navigation(c("Page one", "Page two")),
bslib::navset_hidden(
id = "tabs",
bslib::nav_panel("page_one", shiny::actionButton("next_btn", "Next")),
bslib::nav_panel("page_two", "Page two content")
)
)
server <- function(input, output, session) {
shiny::observeEvent(input$next_btn, {
shinyGovstyle::navigate_to(session, "tabs", "page_two")
})
}
if (interactive()) shiny::shinyApp(ui = ui, server = server)
# Mismatched inputId and panel value — name the panel explicitly.
# The nav links use an `sn_` prefix on their inputIds so they don't clash
# with any other inputs in the app. The panel values are unrelated names.
ui <- shinyGovstyle::gov_page(
shinyGovstyle::service_navigation(
# names = link text shown to the user, values = nav inputIds
c(Home = "sn_home", Cookies = "sn_cookies")
),
bslib::navset_hidden(
id = "tabs",
# first arg of nav_panel() is the panel value
bslib::nav_panel("start", shiny::actionButton("cookies_btn", "Cookies")),
bslib::nav_panel("policy", "Cookies content")
)
)
server <- function(input, output, session) {
shiny::observeEvent(input$cookies_btn, {
# inputId = nav link to highlight; panel = tab panel to show
shinyGovstyle::navigate_to(
session, "tabs", inputId = "sn_cookies", panel = "policy"
)
})
}
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.