如何在服务器端更改 tabPanel 标题的颜色?

How can I change the color of tabPanel title on the server side?

在闪亮的 UI 端,我的代码是:

mainPanel(uiOutput('my_tabsetpanel'))

在服务器端我有:

output$my_tabsetpanel <- renderUI({
    tabPanel(mytabtitle, DT::dataTableOutput(id))
})

如何只更改选项卡标题的颜色?

以下是如何将非活动标签的标题显示为红色,将活动标签的标题显示为蓝色:

shinyApp(
  ui = fluidPage(
    tags$head(
      tags$style(
        HTML("li>a {color: red;} .nav-tabs>li.active>a {color: blue;}"))),
    mainPanel(
      tabsetPanel(
        tabPanel("Plot", p("plot")),
        tabPanel("Summary", p("summary")),
        tabPanel("Table", p("table"))
      )
    )
  ),
  server = function(...){}
)

您可以将标题包裹在 div 中并更改样式。

这是一个例子:

library(shiny)

ui <- fluidPage(
        mainPanel(uiOutput('my_tabsetpanel'))
)

server <- function(input, output) {
    output$my_tabsetpanel <- renderUI({
        tabsetPanel(tabPanel(div("mytabtitle", style = "color: red;"), "my content"))
    })
}

shinyApp(ui = ui, server = server)

结果: