# Controlbar example
if (interactive()) {
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(),
controlbar = dashboardControlbar(
skin = "dark",
controlbarMenu(
id = "menu",
controlbarItem(
"Tab 1",
"Welcome to tab 1"
),
controlbarItem(
"Tab 2",
"Welcome to tab 2"
)
)
),
title = "Right Sidebar"
),
server = function(input, output) { }
)
}
# Toggle the dashboard controlbar
if (interactive()) {
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
actionButton(inputId = "controlbarToggle", label = "Toggle Controlbar")
),
controlbar = dashboardControlbar(id = "controlbar")
),
server = function(input, output, session) {
observeEvent(input$controlbar, {
if (input$controlbar) {
showModal(modalDialog(
title = "Alert",
"The controlbar is opened.",
easyClose = TRUE,
footer = NULL
))
}
})
observeEvent(input$controlbarToggle, {
updateControlbar("controlbar")
})
observe({
print(input$controlbar)
})
}
)
}
# controlbar with controlbarMenu
if (interactive()) {
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(),
controlbar = dashboardControlbar(
id = "controlbar",
controlbarMenu(
id = "menu",
controlbarItem(
"Tab 1",
"Welcome to tab 1"
),
controlbarItem(
"Tab 2",
"Welcome to tab 2"
)
)
)
),
server = function(input, output, session) {
observeEvent(input$menu, {
showModal(modalDialog(
title = "Alert",
sprintf(" %s is active", input$menu),
easyClose = TRUE,
footer = NULL
))
})
}
)
}
# Update a controlbar menu
if (interactive()) {
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
radioButtons("controller", "Controller", choices = c(1, 2, 3))
),
controlbar = dashboardControlbar(
id = "controlbar",
controlbarMenu(
id = "menu",
controlbarItem(
paste0("Tab", 1),
paste("Welcome to tab", 1)
),
controlbarItem(
paste0("Tab", 2),
paste("Welcome to tab", 2)
),
controlbarItem(
paste0("Tab", 3),
paste("Welcome to tab", 3)
)
)
)
),
server = function(input, output, session) {
observeEvent(input$controller, {
updateControlbarMenu(
"menu",
selected = paste0("Tab", input$controller)
)
})
}
)
}
Run the code above in your browser using DataLab