在 R Shiny 中更改侧边栏菜单项颜色
Change sidebar menu item color in R Shiny
谁能告诉我更改蓝线颜色的标签名称(请参阅 Shiny Dashboard 中 menuItem 中的图像。这是更改 bg 颜色的代码侧边栏菜单项。
.skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
background-color: rgb(107,194,0);
color: rgb(255,255,255);font-weight: bold;font-size: 18px;
}
同样,希望自定义蓝线的颜色。
编辑: 添加了完整代码 - 除了蓝线之外,所有其他部分的颜色都已自定义。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(
),
dashboardSidebar(
sidebarMenu(
menuItem("Folder", tabName = "root", icon = icon("folder")),
menuItem("My Home", tabName = "home", icon = icon("home")),
menuItem("Document", tabName = "document", icon = icon("document"))
)
),
dashboardBody(
tags$head(tags$style(HTML('
/* logo */
.skin-blue .main-header .logo {
background-color: rgb(255,255,255); color: rgb(0,144,197);
font-weight: bold;font-size: 24px;text-align: Right;
}
/* logo when hovered */
.skin-blue .main-header .logo:hover {
background-color: rgb(255,255,255);
}
/* navbar (rest of the header) */
.skin-blue .main-header .navbar {
background-color: rgb(255,255,255);
}
/* main sidebar */
.skin-blue .main-sidebar {
background-color: rgb(255,125,125);;
}
# /* main body */
# .skin-blue .main-body {
# background-color: rgb(0,144,197);
# }
/* active selected tab in the sidebarmenu */
.skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
background-color: rgb(107,194,0);
color: rgb(255,255,255);font-weight: bold;font-size: 18px;
}
/* other links in the sidebarmenu */
.skin-blue .main-sidebar .sidebar .sidebar-menu a{
background-color: rgb(255,125,125);
color: rgb(255,255,255);font-weight: bold;
}
/* other links in the sidebarmenu when hovered */
.skin-blue .main-sidebar .sidebar .sidebar-menu a:hover{
background-color: rgb(232,245,251);color: rgb(0,144,197);font-weight: bold;
}
/* toggle button color */
.skin-blue .main-header .navbar .sidebar-toggle{
background-color: rgb(255,255,255);color:rgb(0,144,197);
}
/* toggle button when hovered */
.skin-blue .main-header .navbar .sidebar-toggle:hover{
background-color: rgb(0,144,197);color:rgb(255,255,255);
}
# ')))
))
server <- shinyServer(function(input, output, session) {
})
shinyApp(ui, server)
可以使用以下方法更改颜色CSS
.skin-blue .sidebar-menu > li.active > a {
border-left-color: #ff0000;
}
请注意,如果您更改仪表板的皮肤主题,您可能还需要更改此处的 CSS,因为它引用了 .skin-blue
主题。另请注意,将鼠标悬停在菜单项上时,这不会改变蓝色条的颜色。为此,将上面的 CSS 更改为
.skin-blue .sidebar-menu > li.active > a,
.skin-blue .sidebar-menu > li:hover > a {
border-left-color: #ff0000;
}
谁能告诉我更改蓝线颜色的标签名称(请参阅 Shiny Dashboard 中 menuItem 中的图像。这是更改 bg 颜色的代码侧边栏菜单项。
.skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
background-color: rgb(107,194,0);
color: rgb(255,255,255);font-weight: bold;font-size: 18px;
}
同样,希望自定义蓝线的颜色。
编辑: 添加了完整代码 - 除了蓝线之外,所有其他部分的颜色都已自定义。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(
),
dashboardSidebar(
sidebarMenu(
menuItem("Folder", tabName = "root", icon = icon("folder")),
menuItem("My Home", tabName = "home", icon = icon("home")),
menuItem("Document", tabName = "document", icon = icon("document"))
)
),
dashboardBody(
tags$head(tags$style(HTML('
/* logo */
.skin-blue .main-header .logo {
background-color: rgb(255,255,255); color: rgb(0,144,197);
font-weight: bold;font-size: 24px;text-align: Right;
}
/* logo when hovered */
.skin-blue .main-header .logo:hover {
background-color: rgb(255,255,255);
}
/* navbar (rest of the header) */
.skin-blue .main-header .navbar {
background-color: rgb(255,255,255);
}
/* main sidebar */
.skin-blue .main-sidebar {
background-color: rgb(255,125,125);;
}
# /* main body */
# .skin-blue .main-body {
# background-color: rgb(0,144,197);
# }
/* active selected tab in the sidebarmenu */
.skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
background-color: rgb(107,194,0);
color: rgb(255,255,255);font-weight: bold;font-size: 18px;
}
/* other links in the sidebarmenu */
.skin-blue .main-sidebar .sidebar .sidebar-menu a{
background-color: rgb(255,125,125);
color: rgb(255,255,255);font-weight: bold;
}
/* other links in the sidebarmenu when hovered */
.skin-blue .main-sidebar .sidebar .sidebar-menu a:hover{
background-color: rgb(232,245,251);color: rgb(0,144,197);font-weight: bold;
}
/* toggle button color */
.skin-blue .main-header .navbar .sidebar-toggle{
background-color: rgb(255,255,255);color:rgb(0,144,197);
}
/* toggle button when hovered */
.skin-blue .main-header .navbar .sidebar-toggle:hover{
background-color: rgb(0,144,197);color:rgb(255,255,255);
}
# ')))
))
server <- shinyServer(function(input, output, session) {
})
shinyApp(ui, server)
可以使用以下方法更改颜色CSS
.skin-blue .sidebar-menu > li.active > a {
border-left-color: #ff0000;
}
请注意,如果您更改仪表板的皮肤主题,您可能还需要更改此处的 CSS,因为它引用了 .skin-blue
主题。另请注意,将鼠标悬停在菜单项上时,这不会改变蓝色条的颜色。为此,将上面的 CSS 更改为
.skin-blue .sidebar-menu > li.active > a,
.skin-blue .sidebar-menu > li:hover > a {
border-left-color: #ff0000;
}