2017-11-29 2 views
0

Ich möchte Rest glänzenden App-Code nur ausführen, wenn Modal-Dialogfeld geschlossen ist. Wie kann ich das erreichen?R Shiny Stop-Code-Ausführung, bis Modal geschlossen ist

Hier einfacher Code:

# ui.R 
actionButton("loadData", label = "Button", icon = icon("mail-forward")) 

# server.R 
observeEvent(input$loadData, { 

    showModal(modalDialog(
    title = modal.title, 
    textInput("newName", "Enter file name:", value = ""), 
    easyClose = TRUE, 
    footer = list(
     actionButton("confirmName", "OK"), 
     modalButton("Cancel")) 
)) 

    # ...code to be executed after modal is closed... 

}) 

Antwort

0

Neues event handler, den Code ausführt, wenn die OK-Aktionstaste angeklickt wurde, und schließt auch die modale mit removeModal.

library(shiny) 

ui <- fluidPage(
    actionButton("loadData", label = "Button", icon = icon("mail-forward")), 
    verbatimTextOutput("filename") 
) 

server <- function(input, output, session) { 
    observeEvent(input$loadData, { 
    showModal(modalDialog(
     title = "title", 
     textInput("newName", "Enter file name:", value = ""), 
     easyClose = TRUE, 
     footer = list(
     actionButton("confirmName", "OK"), 
     modalButton("Cancel")) 
    )) 
    }) 

    output$filename <- eventReactive(input$confirmName, { 
    message("Closing modal") 
    removeModal() 
    input$newName 
    }) 
} 

shinyApp(ui, server) 

Es ist ein Beispiel dafür in der Dokumentation: https://shiny.rstudio.com/reference/shiny/latest/modalDialog.html