我只想在模式对话框关闭时执行其余的 Shiny 应用程序代码。我怎样才能做到这一点?
这里简单的代码:
# 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...
})
最佳答案
创建 event handler单击确定操作按钮时执行代码,并使用 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)
文档中有一个例子:https://shiny.rstudio.com/reference/shiny/latest/modalDialog.html
关于R Shiny 停止代码执行,直到模态关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47563372/