如何在Shiny中为selectInput占位符提示着色?

时间:2019-03-15 15:40:44

标签: css r shiny

我想在SelectInput框(段迁移)中显示蓝色的“选择”提示,以使其看起来与其他输入框相似,但失败了。 enter image description here

这是我在UI部分使用的代码段:

  column(width=2,
       selectInput(inputId = "SEG_MIG",
                   label = "Segment Migration",
                   choices =c("Choose"='', "ALL",
                              unique(sort(as.character(final_data$`SEG MIG`)))),
                   multiple = TRUE
                   ))

使用此代码,在左侧两个输入框中选择的元素显示为蓝色

  tags$style(type='text/css', ".selectize-input { font-size: 16px; line-height: 16px; color: blue;} 
                           .selectize-dropdown { background: grey; color: white; font-size: 12px; line-height: 12px; }"),

我不确定我在这里错过了什么。任何建议将不胜感激。

1 个答案:

答案 0 :(得分:1)

这是控制选项,项目和占位符样式的CSS。

library(shiny)

css <- "
.selectize-dropdown-content .option {
  color: blue;
}
.selectize-input .item {
  color: red !important;
  background-color: yellow !important;
}
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
  color: pink;
}
::-moz-placeholder { /* Firefox 19+ */
  color: pink;
}
:-ms-input-placeholder { /* IE 10+ */
  color: pink;
}
:-moz-placeholder { /* Firefox 18- */
  color: pink;
}"

ui <- fluidPage(
  tags$head(
    tags$style(HTML(css))
  ),
  column(width=2,
         selectInput(inputId = "SEG_MIG",
                     label = "Segment Migration",
                     choices = c("Choose"='', "ALL", "AAA", "BBB"),
                     multiple = TRUE
         )
  )
)

server <- function(input, output) {}

shinyApp(ui, server)

enter image description here

相关问题