在dropdrop,shinyWidgets的背景颜色

时间:2018-05-31 11:45:09

标签: css r shiny

如何从shinyWidgets更改下拉菜单的颜色(不是按钮,而是打开的菜单)。我假设,我需要一些CSS代码,但我没有很多CSS经验。

library(shiny)
library(shinyWidgets)
n <- 200

ui <- bootstrapPage(
  numericInput('n', 'Number of obs', n),
  dropdown(
    tags$h4("Advanced"),
    icon = icon("gear"),
    status = "primary", width = "600px",
    inputId="dropdown"
  ),
  tags$style(HTML('#dropdown {background-color: red;}')),
  plotOutput('plot')
)

server <- function(input, output) {
  output$plot <- renderPlot({
    hist(runif(input$n))
  })
}

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:1)

您可以使用CSS选择器#sw-content-dropdown, .sw-dropdown-in,例如:

library(shiny)
library(shinyWidgets)
n <- 200

ui <- bootstrapPage(

  dropdown(
    tags$h4("Advanced"),
    numericInput('n', 'Number of obs', n),
    icon = icon("gear"),
    status = "primary", width = "600px",
    inputId="dropdown"
  ),
  tags$style(HTML('#sw-content-dropdown, .sw-dropdown-in {background-color: red;}')),
  plotOutput('plot')
)

server <- function(input, output) {
  output$plot <- renderPlot({
    hist(runif(input$n))
  })
}

shinyApp(ui = ui, server = server)