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

标签 r shiny modal-dialog

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

相关文章:

r - 如何在 R-2.14 中使用新的 'ByteCompile' 字段?

r - Shiny 的 DT "rows_selected"和 "rows_all"已弃用?

单击按钮时不会显示 jQuery 模态

modal-dialog - _NET_WM_STATE_MODAL 的预期行为是什么?

css - shinyjqui orderinput 按钮大小 [CSS]

javascript - CSS3 Image Modal (Advanced) .. 多一张图片?

r - 清除 R 工作区中的所有用户定义对象

r - 扩展 data.table 以创建分组的主体和别名组合

r - R Markdown 中的内联 dplyr

r - 突出显示 select Item 指向的 R 传单多边形(无需单击它)