1

I am working on a shiny app that has multiple selectInput under a dropDownButton menu. Problem is that when users select one selectInput the dropdownButton closes. For selecting all the selectInput users need to click on the dropdownButton multiple times to open the menu. Is there any way to keep the dropdownButton menu open until the user hits the submit button? Below is an example app.



library("shiny")
library("shinyWidgets")


ui <- fluidPage(
  
  dropdownButton(
    tags$h3("List of Inputs"),
    selectInput(inputId = 'xcol',
                label = 'X Variable',
                choices = names(iris)),
    
    selectInput(inputId ='ycol',
                label  = 'Y variable',
                choices= c("A","B","C")) ,
    actionButton(inputId = "submit1",
                 label = "Submit"),
    circle = TRUE, 
    status = "primary",
    inputId = "mydropdown",
    icon = icon("gear"), width = "700px"
  
    
  )
)





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

shinyApp(ui = ui, server = server)



Tanzir
  • 11
  • 1

1 Answers1

0

You can use toggleDropdownButton in an observeEvent() to keep it open as shown below.

library("shiny")
library("shinyWidgets")

ui <- fluidPage(
  dropdownButton(
    tags$h3("List of Inputs"),
    selectInput(inputId = 'xcol',
                label = 'X Variable',
                choices = names(iris)),
    
    selectInput(inputId ='ycol',
                label  = 'Y variable',
                choices= c("A","B","C")) ,
    actionButton(inputId = "submit1",
                 label = "Submit"),
    circle = TRUE, 
    status = "primary",
    inputId = "mydropdown",
    icon = icon("gear"), width = "700px"
  )
)
server <- function(input, output, session) {
  observeEvent(list(input$xcol, input$ycol), {
    toggleDropdownButton(inputId = "mydropdown")
  }, ignoreInit = TRUE)
}

shinyApp(ui = ui, server = server)

output

YBS
  • 19,324
  • 2
  • 9
  • 27
  • Thanks for the answer YBS, but it's not keeping the dropdown menu open. – Tanzir Aug 21 '21 at 04:10
  • If it closes for you, the toggleDropdownButton should open it again. Otherwise you have a different issue. – YBS Aug 21 '21 at 12:16
  • Hi @YBS, to open it again I need to click on the `dropdownButton` again. I am looking for a way that it will be open until all `selectInput` are selected and the user clicks on the submit button. – Tanzir Aug 21 '21 at 16:38
  • @Tanzir, I thought my picture is showing your desired behavior. At least it does stay open until I select both `selectInput`. Not sure why it does not for you. – YBS Aug 21 '21 at 19:13