navbarTab | R Documentation |
Similar to menuItem but for the dashboardHeader.
Like sidebarMenu but inside dashboardHeader.
navbarTab(text, ..., tabName = NULL, icon = NULL, .list = NULL)
navbarMenu(..., id = NULL)
updateNavbarTabs(
session = shiny::getDefaultReactiveDomain(),
inputId,
selected = NULL
)
text |
Tab text. |
... |
Slot for navbarTab. |
tabName |
Should correspond exactly to the tabName given in tabItem. |
icon |
An icon tag, created by shiny::icon. If NULL, don't display an icon. |
.list |
Use this slot if you had to programmatically pass navbarTab like with lapply. |
id |
Menu id. Useful to leverage updateNavbarTabs on the server. |
session |
Shiny session object. |
inputId |
The id of the |
selected |
If |
You can nest navbarTab so it does like menuSubItem. This is to avoid to create too many functions.
if (interactive()) {
library(shiny)
library(bs4Dash)
tabs <- tabItems(.list = lapply(1:7, function(i) {
tabItem(tabName = sprintf("Tab%s", i), sprintf("Tab %s", i))
}))
shinyApp(
ui = dashboardPage(
header = dashboardHeader(
navbarMenu(
id = "navmenu",
navbarTab(tabName = "Tab1", text = "Tab 1"),
navbarTab(tabName = "Tab2", text = "Tab 2"),
navbarTab(
text = "Menu",
dropdownHeader("Dropdown header"),
navbarTab(tabName = "Tab3", text = "Tab 3"),
dropdownDivider(),
navbarTab(
text = "Sub menu",
dropdownHeader("Another header"),
navbarTab(tabName = "Tab4", text = "Tab 4"),
dropdownHeader("Yet another header"),
navbarTab(tabName = "Tab5", text = "Tab 5"),
navbarTab(
text = "Sub sub menu",
navbarTab(tabName = "Tab6", text = "Tab 6"),
navbarTab(tabName = "Tab7", text = "Tab 7")
)
)
)
)
),
body = dashboardBody(tabs),
controlbar = dashboardControlbar(
sliderInput(
inputId = "controller",
label = "Update the first tabset",
min = 1,
max = 4,
value = 1
)
),
sidebar = dashboardSidebar(disable = TRUE)
),
server = function(input, output, session) {
observeEvent(input$controller, {
updateNavbarTabs(
session,
inputId = "navmenu",
selected = paste0("Tab", input$controller)
)
},
ignoreInit = TRUE
)
}
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.