dreamRs / shinyWidgets

shinyWidgets : Extend widgets available in shiny
https://dreamrs.github.io/shinyWidgets/
GNU General Public License v3.0
832 stars 153 forks source link

dropdownButton does not work with Bootstrap 5 via bslib #425

Closed MattCowgill closed 3 years ago

MattCowgill commented 3 years ago

Hi, If I configure a Shiny app to use Bootstrap 5 via bslib::bs_theme(version = "5"), shinyWidgets::dropdownButton() stops working. I have provided an example below. The button displays in the UI, but does not respond when clicked. Note that the current bslib (>= 0.3.0) is required to use Bootstrap 5. Thank you.

library(shiny)
library(shinyWidgets)
library(bslib)

ui <- fluidPage(
  theme = bs_theme(version = "5",
                   bootswatch = "minty"),
  dropdownButton(
    inputId = "mydropdown",
    label = "Controls",
    icon = icon("sliders"),
    status = "primary",
    circle = FALSE,
    sliderInput(
      inputId = "n",
      label = "Number of observations",
      min = 10, max = 100, value = 30
    ),
    prettyToggle(
      inputId = "na",
      label_on = "NAs keeped",
      label_off = "NAs removed",
      icon_on = icon("check"),
      icon_off = icon("remove")
    )
  ),
  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)
pvictor commented 3 years ago

Should work better if you re-install from GitHub, but note that you risk to encounter some troubles with other widgets by using Bootstrap 5, you're welcome to report them here.

Victor

MattCowgill commented 3 years ago

Great, the GitHub version works, thank you @pvictor. Thanks as well for a useful package.