在R Shiny中更改selectInput的背景颜色

Fel*_*ann 5 css r shiny

我的示例代码:

library(shiny)

server <- function(input, output) {
}

ui <- fluidPage(
  br(),
  selectInput("select1", "Choose: ", c("Alt1.1", "Alt1.2"), selected = c("Alt1.1"), selectize = FALSE, multiple = TRUE),
  br(),
  selectInput("select2", "Choose: ", c("Alt2.1", "Alt2.2"), selected = c("Alt2.1"), selectize = FALSE, multiple = TRUE)
)

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

我如何更改代码,使小部件的背景颜色为红色,为select1蓝色select2

编辑:

我尝试了这个:

div(selectInput("select1", "Choose: ", c("Alt1.1", "Alt1.2"), selected = c("Alt1.1"), selectize = FALSE, multiple = TRUE), style = "background-color: red")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

但这不是我想要的!相反,我希望选项的背景为红色!

Flo*_*ian 6

根据以下评论的要求进行编辑

您可以通过样式标签添加CSS,如下所示:

library(shiny)

server <- function(input, output) {
}

ui <- fluidPage(
  br(),
  tags$style("#select1 {border: 2px solid #dd4b39;}"),
  selectInput("select1", "Choose: ", c("Alt1.1", "Alt1.2"), selected = c("Alt1.1"), selectize = FALSE, multiple = TRUE),
  br(),
  tags$style("#select2 {background-color:blue;}"),
  selectInput("select2", "Choose: ", c("Alt2.1", "Alt2.2"), selected = c("Alt2.1"), selectize = FALSE, multiple = TRUE)
)

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明