I have a shiny app where there are many menuitems with submenuitems. In my code, active submenuitem are highlighted with different color than the non active submenuitems. Can someone help with changing the color of the menuitem (making it same as submenuitem) when any submenuitem is active?
Please refer to screenshot below:- can we change color for "First" as well when "Chart" or "Dashboard" is selected?
Below is the reusable code for this:-
library(shiny)
library(shinydashboard)
library(gapminder)
tabledata<-gapminder
header <- dashboardHeader(
title = "Test Dashboard"
)
sidebar <- dashboardSidebar(
sidebarMenu (
menuItem("First",startExpanded = TRUE,
menuSubItem("Dashboard", tabName = "tab1"),
menuSubItem("Chart", "tab2")
),
menuItem("Second",startExpanded = TRUE,
menuSubItem("Detailed_view", tabName = "tab3")
)
)
)
body <- dashboardBody(
tags$head(tags$style(HTML('
/* main sidebar */
.skin-blue .main-sidebar {
background-color: #EBEBEB;
}
/* active selected tab in the sidebarmenu */
.skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
background-color: #E0E0E0;
color: #666666;
}
/* other links in the sidebarmenu */
.skin-blue .main-sidebar .sidebar .sidebar-menu a{
background-color: #EBEBEB;
color: #666666;
}
/* other links in the sidebarmenu when hovered */
.skin-blue .main-sidebar .sidebar .sidebar-menu a:hover{
background-color: #E0E0E0;
color: #000000;
}
'))),
tabItems(
tabItem(tabName = "tab1",
box(title = "Table", width = 10, status = "warning", DT::dataTableOutput("table"))
),
tabItem(tabName = "tab2",
plotOutput("plot1")
)
)
)
ui <- dashboardPage(skin = "blue",header, sidebar, body)
server <- function(input, output) {
output$table = DT::renderDataTable({
DT::datatable(tabledata)
})
output$plot1<-renderPlot({
plot(tabledata$year,tabledata$pop)
})
}
shiny::shinyApp(ui, server)
