0

我正在开发一个在 dropDownButton 菜单下有多个 selectInput 的闪亮应用程序。问题是当用户选择一个 selectInput 时,dropdownButton 会关闭。要选择所有 selectInput 用户需要多次单击下拉按钮以打开菜单。有没有办法让 dropdownButton 菜单保持打开状态,直到用户点击提交按钮?下面是一个示例应用程序。



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)



4

1 回答 1

0

您可以使用toggleDropdownButtoninobserveEvent()保持打开状态,如下所示。

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)

输出

于 2021-08-21T02:52:03.097 回答