首页 > 解决方案 > shinywidget dropdownButton CSS 标签

问题描述

我正在使用 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 按钮和面板?

标签: cssrshinyshinydashboarddropdownbutton

解决方案


我使用了一个示例代码,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)

}
# }

在此处输入图像描述


推荐阅读