Shinywidget dropdownButton CSS标签

时间:2019-02-28 08:39:24

标签: css r shiny shinydashboard dropdownbutton

我正在使用dropdownButton窗口小部件,但我正在与CSS挣扎。 我已经尝试过了:

dropdownButton(inputId = "MyDropDownB1",
   tags$div(style = "background-color: #393D3F !important;",
        checkboxGroupInput(...)
        ),
        circle = F, status = "info", icon = icon("gear"), width = "300px",
        label="Recruitment"
      )

这会更改面板的颜色,但是我仍然有白色边距。

我希望所有CSS都位于特定的.css文件中,而不是位于tag $ div中。我应该在.css文件中使用哪个标签来定位dropdownButton按钮和面板?

1 个答案:

答案 0 :(得分:1)

我使用了shinyWidgets中的示例代码,因为您尚未共享任何MWE

#dropdown-menu-MyDropDownB1您要在CSS中定位的对象。如您所见,这是基于您在id中输入的dropdownButton的名字

# NOT RUN {
## Only run examples in interactive R sessions
if (interactive()) {

  library(shiny)
  library(shinyWidgets)

  ui <- fluidPage(
    tags$head(tags$style(HTML("#dropdown-menu-MyDropDownB1 {
                      background-color: #393D3F !important;}
               ")))
    , 

      dropdownButton(inputId = "MyDropDownB1",

                              checkboxGroupInput("icons", "Choose icons:",
                                                 choiceNames =
                                                   list(icon("calendar"), icon("bed"),
                                                        icon("cog"), icon("bug")),
                                                 choiceValues =
                                                   list("calendar", "bed", "cog", "bug")

                     ),
                     circle = F, status = "info", icon = icon("gear"), width = "300px",
                     label="Recruitment"
      ),

    tags$div(style = "height: 140px;"), # spacing
    verbatimTextOutput(outputId = "out"),
    verbatimTextOutput(outputId = "state")
  )

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

    output$out <- renderPrint({
      cat(
        " # n\n", input$n, "\n",
        "# na\n", input$na
      )
    })

    output$state <- renderPrint({
      cat("Open:", input$mydropdown_state)
    })

  }

  shinyApp(ui, server)

}
# }

enter image description here