Background color of tabs in shiny tabPanel

前端 未结 2 1876
执笔经年
执笔经年 2020-11-30 09:36

I would like to customize a shiny application using tabsetPanels so that the selected panel appears in a black background with white text, and the unselected ta

2条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 09:56

    The above example is broken apparently (from version 0.14.0), probably due to a Shiny css change. Additionally the title of the post promises more than the actual question and solution actually covered. So I wrote a new more comprehensive example.

    • It sets the default tab background to be aqua and black text.
    • It sets the color of several tabs to be explicit colors (when they are not active) with white text.
    • It sets the active tab background to be black with white text.

    Whether or not all these colors are a good idea from a UI point of view is another question...

    Here is the code:

    library(shiny)
    ui <-shinyUI(fluidPage(
      h1("Colored Tabs"),
      tags$style(HTML("
        .tabbable > .nav > li > a                  {background-color: aqua;  color:black}
        .tabbable > .nav > li > a[data-value='t1'] {background-color: red;   color:white}
        .tabbable > .nav > li > a[data-value='t2'] {background-color: blue;  color:white}
        .tabbable > .nav > li > a[data-value='t3'] {background-color: green; color:white}
        .tabbable > .nav > li[class=active]    > a {background-color: black; color:white}
      ")),
      tabsetPanel(
        tabPanel("t0",h2("normal tab")),
        tabPanel("t1",h2("red tab")),
        tabPanel("t2",h2("blue tab")), 
        tabPanel("t3",h2("green tab")),
        tabPanel("t4",h2("normal tab")),
        tabPanel("t5",h2("normal tab"))
      )
    ))
    server <- function(input, output) {}
    shinyApp(ui=ui,server=server)
    

    Here is a screen shot:

    And in case this breaks again, and the code has to be adjusted, here is the current css/html that is producing this:

    
      

    Colored Tabs

    normal tab

    red tab

    blue tab

    green tab

    normal tab

    normal tab

提交回复
热议问题