Shiny bsPopover 中单个文本元素的字体颜色

Font color for single text element in Shiny bsPopover

我想更改 bsPopover 内容参数中的一部分文本的字体颜色。

此语法适用于服务器端,但不适用于 bsPopover 函数的内容参数:


library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyBS)

ui <- dashboardPagePlus(title = 'My Title',
                        ###### Header ####
                        header=dashboardHeaderPlus(
                          title = 'Title'),
      sidebar=dashboardSidebar(
                            disable = TRUE),
                          ###### Body ####
      body = dashboardBody(
                   fluidRow(
                     bsPopover(id = 'attend',
                               title = '', 
                               content = HTML(paste0('<span style=\"color:', '#22a783', '\">', 
                                                      'Green', '</span>', 
                                                      '<br>', 'Red', '<br>', 'Blue', '<br>','Black')), 
                               placement = "bottom", 
                               trigger = "hover",
                               options = NULL),
                     actionButton(inputId = "attend", 
                                  label = "", 
                                  icon = icon('info')))))
#################### SERVER   #################### 
server = function(input, output, session) { 
}
# Run the application
shinyApp(ui = ui, server = server)

我想让文本 "green" 显示为绿色。文本,"red",显示为红色等

我可以更改 css 中的所有文本颜色,但我似乎无法微调 css

之外的单个文本元素

感谢任何想法。

作为替代方案,您可以使用 shinyWidgets 中的 dropMenu,并直接在其中使用 HTML 标签:

library(shiny)
library(shinydashboard)
library(shinyWidgets)

ui <- dashboardPage(
  title = 'My Title',
  ###### Header ####
  header=dashboardHeader(
    title = 'Title'
  ),
  sidebar=dashboardSidebar(
    disable = TRUE
  ),
  ###### Body ####
  body = dashboardBody(
    fluidRow(
      dropMenu(
        actionButton(
          inputId = "attend", 
          label = "", 
          icon = icon('info')
        ),
        tags$div(
          tags$span(style = "color: #22a783;", "green"),
          tags$span(style = "color: red;", "Red"),
          tags$span(style = "color: green;", "Green"),
          "Black"
        ),
        placement = "bottom",
        trigger = "mouseenter"
      )
    )
  )
)
#################### SERVER   #################### 
server = function(input, output, session) { 
}
# Run the application
shinyApp(ui = ui, server = server)