简体   繁体   English

如何在Shinydashboard中更改所选menuItem的背景颜色?

[英]How can I change the background color of the selected menuItem in shinydashboard?

I have included a simple example code. 我提供了一个简单的示例代码。 If I selected Widgets , the background color of the Widgets menuItem should change. 如果我选择了Widgets ,那么Widgets menuItem的背景色应该改变。

The code is as follows 代码如下

    ## Only run this example in interactive R sessions
if (interactive()) {

  ui <- dashboardPage(
    dashboardHeader(title = "Simple tabs"),
    dashboardSidebar(
      sidebarMenu(

        menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
        menuItem("Widgets", tabName = "widgets", icon = icon("th"))
      )

    ),
    dashboardBody(
      tabItems(
        tabItem(tabName = "dashboard",
                h2("Dashboard tab content")
        ),
        tabItem(tabName = "widgets",
                h2("Widgets tab content")
        )
      )
    )
  )

  server <- function(input, output, session) {


    }


}
shinyApp(ui, server)

Should I add a CSS tag? 我应该添加CSS标签吗? Thank You in advance! 先感谢您!

Try the toggleClass function to toggle between CSS classes. 尝试使用toggleClass函数在CSS类之间进行切换。 Usage and examples can be found here . 用法和示例可以在这里找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM