R语言 通过单击按钮关闭shinyWidgets下拉按钮

du7egjpx  于 2022-12-20  发布在  其他
关注(0)|答案(3)|浏览(121)

在一个闪亮的应用程序中,有没有办法在点击按钮后关闭dropdownButton的上下文菜单?我在dropdownButton文档中寻找类似closed/opened的属性,但没有找到任何东西,但我相信一定有办法做到这一点。
这是一个示例应用程序:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  dropdownButton(
    actionButton("button", "Press this Button to close the dropdownButton!"),
    circle = TRUE, status = "primary", icon = icon("user-circle")
  )
)

server <- function(input, output) {
  observeEvent(
    input$button, {
      # Set dropdownButton closed
      print("Test")
    }
  )

}

shinyApp(ui = ui, server = server)
llmtgqce

llmtgqce1#

你是说像这样的东西吗?

library(shiny)
  library(shinyWidgets)

  ui <- fluidPage(
    uiOutput('help')

  )

  server <- function(input, output) {
    observeEvent(
      input$button, {
        shinyjs::hide("button")
        #output$help <- renderUI({} ) 

      }
    )
    output$help <- renderUI(dropdownButton(
      actionButton("button", "Press this Button to close the dropdownButton!"),
      circle = TRUE, status = "primary", icon = icon("user-circle")
    ) ) 

  }

  shinyApp(ui = ui, server = server)
6za6bjd0

6za6bjd02#

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  uiOutput('help')

)

server <- function(input, output) {
  observeEvent(
    input$button, {
      shinyjs::hideElement("dropdown-menu")

    }
  )
  output$help <- renderUI(dropdownButton(
    actionButton("button", "Press this Button to close the dropdownButton!"),
    circle = TRUE, status = "primary", icon = icon("user-circle")
  ) ) 

}

shinyApp(ui = ui, server = server)
unftdfkk

unftdfkk3#

通过从下拉菜单中删除**“sw-show”**类,其上下文将消失。

  • 使用shinyjs::removeClass来执行此操作。
  • 不要忘记在菜单ID中添加**sw-content-**前缀。

'

library(shiny)
library(shinyjs)
library(shinyWidgets)
ui <- fluidPage(
  useShinyjs(),
  uiOutput('drop_down_output')
  
)

server <- function(input, output) {
  
  output$drop_down_output <- renderUI({
    dropdown( 
      inputId = 'drop_down_1',
      actionButton("button", "Run!")
    ) 
  }) 
  
  observeEvent(input$button,{
    shinyjs::removeClass(id = 'sw-content-drop_down_1', class = 'sw-show')
  })

}
shinyApp(ui = ui, server = server)

'

相关问题