【问题标题】:How to change color in shiny dashboard?如何在闪亮的仪表板中更改颜色?
【发布时间】:2015-10-21 01:47:54
【问题描述】:

(来自闪亮的谷歌群组的交叉帖子)

有人可以指出我必须修改闪亮仪表板颜色的标签名称吗?

修改自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”上的项目时更改颜色。

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    也许这个包可以帮助你进一步:

    https://github.com/dreamRs/fresh

    它允许很好地设置自定义主题和颜色,而无需自己处理 CSS 定义 - 但可以创建它们以供重复使用。

    可以在此处找到更多信息(一本包含更多主题的详尽书籍!):https://unleash-shiny.rinterface.com/beautify-with-fresh.html

    【讨论】:

      【解决方案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;
                                        }
      
      

      【讨论】:

        【解决方案3】:

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

        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 以指出它修改了什么。

        【讨论】:

        • 太好了,谢谢。关于如何更改侧边栏中的文本颜色的任何想法?
        • 您可以在 CSS 中为 .skin-blue .main-sidebar .sidebar .sidebar-menu a 设置 color 参数。例如,color: #000000; 将使文本变黑(我将其添加到我发布的代码中)
        • 谢谢!刚刚发现了 chrome 中的开发人员工具,这使得过程非常简单,因为我可以很容易地看到页面中存在哪些元素。 developer.chrome.com/devtools
        • 当菜单中的一项被选中并且用户悬停在树视图菜单中时,如何更改树视图菜单的左边框颜色?
        【解决方案4】:

        感谢您的帖子。我认为您应该添加“悬停时切换按钮”以使其完成。示例代码如下:

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

        【讨论】:

          猜你喜欢
          • 2017-12-14
          • 2015-06-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-07-07
          • 1970-01-01
          • 2020-09-12
          相关资源
          最近更新 更多