如何在Shiny Dashboard中更改颜色?

29

(来自闪亮的Google小组的跨贴)

请问有人能指出我修改Shiny仪表板颜色时需要修改哪些标签名称吗?

这是从http://rstudio.github.io/shinydashboard/appearance.html#long-titles改编而来的,它将会把我的仪表板左上角变为橙色。

tags$head(tags$style(HTML('
        .skin-blue .main-header .logo {
                              background-color: #f4b943;
                              }
                              .skin-blue .main-header .logo:hover {
                              background-color: #f4b943;
                              }
                              ')))

我不清楚如何将标题和侧边栏的其余部分改成橙色,并且当“SideBarMenu”上的项目被选中/突出显示时,我该如何更改颜色。

4个回答

75

根据您发布的链接示例,您可以尝试:

ui.R

dashboardPage(
                dashboardHeader(
                        title = "Example of a long title that needs more space",
                        titleWidth = 450
                ),
                dashboardSidebar( sidebarMenu(
                        menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
                        menuItem("Widgets", icon = icon("th"), tabName = "widgets",
                                 badgeLabel = "new", badgeColor = "green")
                )),
                dashboardBody(
                        # Also add some custom CSS to make the title background area the same
                        # color as the rest of the header.
                        tags$head(tags$style(HTML('
        /* logo */
        .skin-blue .main-header .logo {
                              background-color: #f4b943;
                              }

        /* logo when hovered */
        .skin-blue .main-header .logo:hover {
                              background-color: #f4b943;
                              }

        /* navbar (rest of the header) */
        .skin-blue .main-header .navbar {
                              background-color: #f4b943;
                              }        

        /* main sidebar */
        .skin-blue .main-sidebar {
                              background-color: #f4b943;
                              }

        /* active selected tab in the sidebarmenu */
        .skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
                              background-color: #ff0000;
                              }

        /* other links in the sidebarmenu */
        .skin-blue .main-sidebar .sidebar .sidebar-menu a{
                              background-color: #00ff00;
                              color: #000000;
                              }

        /* other links in the sidebarmenu when hovered */
         .skin-blue .main-sidebar .sidebar .sidebar-menu a:hover{
                              background-color: #ff69b4;
                              }
        /* toggle button when hovered  */                    
         .skin-blue .main-header .navbar .sidebar-toggle:hover{
                              background-color: #ff69b4;
                              }
                              ')))
                )


)

我在CSS中进行了注释以指出它修改的内容。


太好了,谢谢。你有什么想法可以改变侧边栏的文本颜色吗? - Iain
2
你可以在 .skin-blue .main-sidebar .sidebar .sidebar-menu a 的 CSS 中设置 color 参数。例如,color: #000000; 将使文本变为黑色(我已将其添加到我发布的代码中)。 - NicE
1
谢谢!刚刚发现了Chrome中的开发者工具,这使得整个过程变得非常简单,因为我可以轻松地查看页面中存在哪些元素。https://developer.chrome.com/devtools - Iain
当用户在树形菜单中选择一个项目并悬停时,如何更改树形菜单的左边框颜色? - Skumin

6

感谢您的发布。我认为您应该添加“鼠标悬停时切换按钮”以使其完整。以下是示例代码:

/* toggle button when hovered  */                    
.skin-blue .main-header .navbar .sidebar-toggle:hover{
  background-color: #ff69b4;
}

2
感谢@NicE的回答。另外,如果有人想要控制侧边栏菜单选择区域左边框的颜色强调,可以使用border-left属性:
            /* active selected tab in the sidebarmenu */
            .skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
                                  background-color: #2e6984;
                                  border-left: 3px solid #254264;
                                  }

            /* other links in the sidebarmenu */
            .skin-blue .main-sidebar .sidebar .sidebar-menu a{
                                  background-color: #3E8CB0;
                                  color: #FFFFFF;
                                  }

            /* other links in the sidebarmenu when hovered */
             .skin-blue .main-sidebar .sidebar .sidebar-menu a:hover{
                                  background-color: #2e6984;
                                  border-left: 3px solid #254264;
                                  }


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接