Shiny 中的 SelectizeInput - 将选择的一部分加粗

问题描述 投票:0回答:1

我想更改 SelectizeInput 下拉选项的一部分。例如,如果任何选项以“*”结尾,则“*”应为粗体(或使用更大的字体)。 我不确定个人的选择是否可以以这种方式被操纵。例如:

library(shiny)

ui <- fluidPage(
  selectizeInput("select",
                 label = "Chooose one",
                 choices = c("Option 1", "Option 2 *", "Option 3"))
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

第二个选项末尾应有一个粗体“*”。这能实现吗?

r shiny selectize.js
1个回答
0
投票

div[data-value*="*"]
添加到 CSS 中将模糊匹配任何包含“*”的选项。您对以
the
结尾的任何请求将使用
div[data-value$="the"]
处理。请参阅 https://www.w3.org/TR/selectors/#attribute-substrings 了解更多选项,并感谢 如何根据值更改 css 样式如何通过部分 ID 值选择 CSS 中的元素? 让我到达那里。

library(shiny)

ui <- fluidPage(   tags$head(
    
    tags$style(HTML('
    div[data-value*="*"] {
    font-weight: bold;   }
    '))),   selectizeInput("select",
                 label = "Chooose one",
                 choices = c("Option 1", "Option 2 *", "Option 3")) )

server <- function(input, output, session) {

}

shinyApp(ui, server)
© www.soinside.com 2019 - 2024. All rights reserved.