Change background color of tabPanel when it is active or hover over in Shiny

后端 未结 1 1462
悲&欢浪女
悲&欢浪女 2020-12-20 09:58

I have created an R Shiny app and I would like to change the background color of tabPanel when it is active or when I hover over. I am not sure that I use define the correc

相关标签:
1条回答
  • 2020-12-20 10:26

    Hi you need to tell shiny that the CSS string is HTML with the HTML() function like my example below. Even better but not necessary is to put it in a head tag. I also think you had someproblem in your css code. Be careful to always lead all classes with .

    library(shiny)
    library(shinydashboard)
    
    ui <- function(){
      navbarPage(title = 'Hello', 
                 tabPanel("title2"),
                 tabPanel("title3"),
                 tags$head(
                   tags$style(type = 'text/css', 
                              HTML('.navbar { background-color: red;}
                              .navbar-default .navbar-brand{color: white;}
                              .tab-panel{ background-color: red; color: white}
                              .navbar-default .navbar-nav > .active > a, 
                               .navbar-default .navbar-nav > .active > a:focus, 
                               .navbar-default .navbar-nav > .active > a:hover {
                                    color: #555;
                                    background-color: green;
                                }')
                              )
                  )
                )
    
    }
    
    server <- function(input, output, session){
    }
    
    
    shinyApp(ui = ui, server = server)
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题