nav_select {bslib}R Documentation

Dynamically update nav containers

Description

Functions for dynamically updating nav containers (e.g., select, insert, and remove nav items). These functions require an id on the nav container to be specified.

Usage

nav_select(id, selected = NULL, session = getDefaultReactiveDomain())

nav_insert(
  id,
  nav,
  target = NULL,
  position = c("after", "before"),
  select = FALSE,
  session = getDefaultReactiveDomain()
)

nav_remove(id, target, session = getDefaultReactiveDomain())

nav_show(id, target, select = FALSE, session = getDefaultReactiveDomain())

nav_hide(id, target, session = getDefaultReactiveDomain())

Arguments

id

a character string used to identify the nav container.

selected

a character string used to identify a particular nav() item.

session

a shiny session object (the default should almost always be used).

nav

a nav() item.

target

The value of an existing nav() item, next to which tab will be added. If removing: the value of the nav() item that you want to remove.

position

Should nav be added before or after the target?

select

Should nav be selected upon being inserted?

See Also

nav(), navs_tab().

Examples


can_browse <- function() interactive() && require("shiny")

# Selecting a tab
if (can_browse()) {
  shinyApp(
    page_fluid(
      radioButtons("item", "Choose", c("A", "B")),
      navs_hidden(
        id = "container",
        nav_content("A", "a"),
        nav_content("B", "b")
      )
    ),
    function(input, output) {
      observe(nav_select("container", input$item))
    }
  )
}

# Inserting and removing
if (can_browse()) {
  ui <- page_fluid(
    actionButton("add", "Add 'Dynamic' tab"),
    actionButton("remove", "Remove 'Foo' tab"),
    navs_tab(
      id = "tabs",
      nav("Hello", "hello"),
      nav("Foo", "foo"),
      nav("Bar", "bar tab")
    )
  )
  server <- function(input, output) {
    observeEvent(input$add, {
      nav_insert(
        "tabs", target = "Bar", select = TRUE,
        nav("Dynamic", "Dynamically added content")
      )
    })
    observeEvent(input$remove, {
      nav_remove("tabs", target = "Foo")
    })
  }
  shinyApp(ui, server)
}


[Package bslib version 0.3.1 Index]