How to change the display attributes of SPECIFIC tabs when using tabPanel in navbarPage

与世无争的帅哥 提交于 2021-01-28 08:20:48

问题


In this example,

library(shiny)
ui <- fluidPage(
  tags$style(type = 'text/css', HTML('.navbar {background-color: red;}')),
  navbarPage("",
    tabPanel("Tab 1", icon = icon("user")),
    tabPanel("Tab 2", icon = icon("cog")),
    tabPanel("Tab 3", icon = icon("sliders"))
  )
)
server <- function(input, output, session) {
}
shinyApp(ui, server)

I would like Tab 3 to be special such that it appears different from the rest for:

  • background-color + font-color when not hovered and not selected
  • background-color + font-color when hovered
  • background-color + font-color when selected
  • Bolded font

For the other tabs, I am fine with sticking to the defaults.

None of the threads I came across directly address this issue for me, who has no HTML or CSS background. Some addressed part of the problem for tabsetPanel, but not for navbarPage.

Any advice, or redirection to a tutorial for dummies would be nice enough.

Thanks!


回答1:


library(shiny)
#select more than one Tab you can try
#1. a[data-value='Tab 2'], a[data-value='Tab 3'] {...}
#2. rename Tab 2 and Tab 3 values to Tab 02 and Tab 03 then use a[data-value*='0'] {...}
ui <- fluidPage(
       tags$style(type = 'text/css', 
                  HTML(".container-fluid > .nav > li > 
                        a[data-value='Tab 3'] {background-color: red; color:white}")),
    navbarPage("",
         tabPanel("Tab 1" ,value = "Tab 1" ,icon = icon("user")),
         tabPanel("Tab 2" ,value = "Tab 2" ,icon = icon("cog")),
         tabPanel("Tab 3" ,value = "Tab 3" ,icon = icon("sliders"))
   )
)
server <- function(input, output, session) {}
shinyApp(ui, server)


来源:https://stackoverflow.com/questions/49973388/how-to-change-the-display-attributes-of-specific-tabs-when-using-tabpanel-in-nav

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!