2017-11-21 7 views
0

dropdownButtonのコンテキストメニューをボタンをクリックして光ったアプリに閉じ込める方法はありますか?私はclosed/openedのような属性をdropdownButton文書で探していましたが、何も見つかりませんでしたが、これを行う方法が必要であると信じています。ボタンをクリックしてshinyWidgetsドロップダウンボタンを閉じる

これは、例えばアプリです:あなたはこのような何かを意味するか

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) 
+0

あなたが開いているドロップダウンからドロップダウンを変更するには、 '上記のdivのアリア展開=「true」を' –

+0

@PorkChopはい、そうでない場合は、クラスを制御するために、いくつかの 'JS'を記述する必要があります。私はそれをすることができませんでした:( – amrrs

答えて

2

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) 
+0

ありがとうございます、これが動作します –

+0

これは興味深い解決策です –

1
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) 
+0

こんにちはAlejandroとあなたの応答のためのありがとう。私の質問を少し指定する必要があります。私はボタンが消えてはいけないが、 'dropdownButton'のコンテキストメニューは自動的に閉じます。 –

+1

@FelixGrossmannこの更新されたソリューションを確認してください – amrrs

+1

@amrrsありがとうございます、これが動作します。 –

関連する問題