以下是我的shiny 应用程序的编辑版本:

ui <- tagList(
  fluidPage(
    titlePanel(""),
    tags$head(tags$style(HTML(
      "
        .navbar-default {
            color: red !important;'
        }
        
        "
      ))),
    navbarPage(
      windowTitle = "App Name",
      theme = bs_theme(bootswatch = "flatly",
                       base_font = font_google("Lato"),
                       primary = "#333F50",
                       bg = "white",
                       fg = "#D67540"),
      title = "I am the title",
      selected = "Main Tab 1",
      tabPanel(title = "Main Tab 1",
               fluidPage(
                 sidebarLayout(
                   sidebarPanel(textInput(inputId = "text_input", label = "Enter text:")),
                   mainPanel(textOutput(outputId = "text_output"))
                 )
               )
               ),
      tabPanel(title = "Main Tab 2",
               fluidPage(
                   fluidRow(
                     column(7,
                            navlistPanel(
                              tabPanel("Tab 1"),
                              tabPanel("Tab 2"),
                              tabPanel("Tab 3"),
                              widths = c(2, 10),
                              well = FALSE)
                            )))
               )
      )
    )
  )

server <- function(input, output){
  output$text_output <- renderText(input$text_input)
}

shinyApp(ui, server)

This is what "Main Tab 1" looks like: Main Tab 1

当链接悬停/选中时,我想将"Main Tab 1"和"Main Tab 2"的文本 colored颜色 从白色更改为粉色,并从蓝绿色更改为红色.

到目前为止,我已经try 了以下方法的许多变体,但都没有成功:

.navbar-default {
   color: red !important;
}

有人知道怎么解决这个问题吗?

如有任何帮助,我们不胜感激:)

推荐答案

我们可以使用下面的css代码块来实现:

library(bslib)
library(shiny)

ui <- tagList(
  fluidPage(
    titlePanel(""),
    tags$head(tags$style(HTML(
      "
        .navbar-default {
            color: red !important;'
        }
        .navbar-default .navbar-nav > .active > a,
        .navbar-default .navbar-nav > li > a:hover {
            color: red !important;
        }
        .navbar-default .navbar-nav > li > a {
            color: pink !important;
        }
        "
    ))),
    navbarPage(
      windowTitle = "App Name",
      theme = bs_theme(bootswatch = "flatly",
                       base_font = font_google("Lato"),
                       primary = "#333F50",
                       bg = "white",
                       fg = "#D67540"),
      title = "I am the title",
      selected = "Main Tab 1",
      tabPanel(title = "Main Tab 1",
               fluidPage(
                 sidebarLayout(
                   sidebarPanel(textInput(inputId = "text_input", label = "Enter text:")),
                   mainPanel(textOutput(outputId = "text_output"))
                 )
               )
      ),
      tabPanel(title = "Main Tab 2",
               fluidPage(
                 fluidRow(
                   column(7,
                          navlistPanel(
                            tabPanel("Tab 1"),
                            tabPanel("Tab 2"),
                            tabPanel("Tab 3"),
                            widths = c(2, 10),
                            well = FALSE)
                   )))
      )
    )
  )
)

server <- function(input, output){
  output$text_output <- renderText(input$text_input)
}

shinyApp(ui, server)

enter image description here

Css相关问答推荐

当鼠标悬停在元素的::第一行时,如何应用样式?

CSS Grid我不想要的东西

我无法在css中设置填充或边距

当滚动量较小时,在滚动问题上动画粘性导航

滚动弹性盒

如何使我的标语(h1元素)不居中对齐?

React Tabs 在 Tabs 之间垂直渲染标签内容

使元素不水平滚动

当父元素处于子元素 input 的焦点状态时更改父元素的样式

semantic-ui-react 使输入使用全宽度可用

父母是内联块,子元素有%填充=奇怪的行为

Angular 导航栏问题

溢出的文本可以居中吗?

如何在 CSS 中绘制一个圆形扇区?

虚拟键盘激活时的屏幕样式

如何对齐标签和文本区域?

通过 Bootstrap4 对列进行排序

是否允许在链接中嵌套链接?

使图像具有响应性 - 最简单的方法

CSS 边距和填充速记属性顺序的助记符