gpt4 book ai didi

R Shiny 停止代码执行,直到模态关闭

转载 作者:行者123 更新时间:2023-12-03 23:17:29 24 4
gpt4 key购买 nike

我只想在模式对话框关闭时执行其余的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com