bs4Dash
bs4Dash copied to clipboard
How to Navigate to a particular sidebar menu item in bs4Dash from the Navbar
I want to be able to navigate to a particular sidebar from the Navbar action button.
I know bs4Dash is a bootstrapping theme, but I am trying to customize a dashboard by moving the sidebar to the top of the navbar.
The only way I know possible is using action buttons like what I have done so far. However, in doing so I still haven't been able to successfully toggle to the right sidebar.
Here is the code
library(shiny)
library(bs4Dash)
shinyApp(
ui = bs4DashPage(
header = bs4DashNavbar(
skin = "light",
status = "white",
border = FALSE,
sidebarIcon = icon("bars"),
compact = FALSE,
controlbarIcon = icon("th"),
actionButton(inputId = "controlbarToggle", label = "Toggle Controlbar", class = "mx-2"),
actionButton(inputId = "socialcardToggle", label = "Toggle Tab 2", class = "mx-2"),
actionButton(inputId = "controlbarToggle", label = "Toggle Controlbar", class = "mx-2")
),
sidebar = bs4DashSidebar(
inputId = "sidebar",
disable = FALSE,
title = "My Dashboard",
skin = "light",
status = "primary",
brandColor = NULL,
url = NULL,
src = "https://cdn-icons-png.flaticon.com/512/2922/2922561.png",
elevation = 4,
opacity = 0.8,
expand_on_hover = TRUE,
bs4SidebarUserPanel(
image = "https://cdn-icons-png.flaticon.com/512/2922/2922510.png",
name = "Dennis"
),
bs4SidebarMenu(
id = "sidebarmenu",
bs4SidebarHeader("Menu1"),
bs4SidebarMenuItem(
"Tab 1",
tabName = "tab1",
icon = icon("user")
#startExpanded = FALSE
),
bs4SidebarMenuItem(
"Tab 2",
tabName = "tab2",
icon = icon("user")
#startExpanded = FALSE
)
)
),
controlbar = bs4DashControlbar(
"Text",
inputId = "controlbar",
disable = FALSE,
skin = "dark",
title = "Controlbar",
width = 250
),
footer = bs4DashFooter(left = "@Dennis", right = NULL),
title = "Basic Dashboard",
body = bs4DashBody(
bs4TabItems(
bs4TabItem(
tabName = "tab1",
bs4Card(
title = "Closable Box Tab 1 with dropdown",
closable = TRUE,
width = 12,
status = "warning",
solidHeader = FALSE,
collapsible = TRUE,
labelText = 1,
labelStatus = "danger",
labelTooltip = "Hi Bro!",
dropdownIcon = "wrench",
p("Box Content")
)
),
bs4TabItem(
tabName = "tab2",
bs4Card(
title = "Closable Box Tab 2 with dropdown",
closable = TRUE,
width = 12,
status = "warning",
solidHeader = FALSE,
collapsible = TRUE,
labelText = 1,
labelStatus = "danger",
labelTooltip = "Hi Bro!",
dropdownIcon = "wrench",
p("Box Content Tab 2")
)
)
)
)
),
server = function(input, output, session) {
observeEvent(input$controlbarToggle, {
updateControlbar(id = "controlbar")
})
observe(print(input$sidebar))
observe(print(input$sidebarmenu))
}
)
```