无法使用removeModal()移除模态对话框。

huangapple go评论99阅读模式
英文:

Cannot remove modal dialog with removeModal()

问题

ui <- fluidPage(
modalDialog(
title = "单击下面以隐藏模态对话框无效",
footer = actionButton("ready", "确定")
)
)
server <- function(input, output, session) {
observeEvent(input$ready, {
removeModal(session)
})
}

这不会产生任何错误,它只是不起作用。我的屏幕变成灰色,模态对话框保持不变,无响应。与此同时,如果我删除我的自定义按钮并使用默认的 "关闭",那么它就能正常工作。我已经尝试过分配ID并删除session参数,以及许多其他方法。我需要模态对话框在UI中(因为我使用的包函数在服务器中不起作用),我需要观察 "确定" 按钮以传递参数。

英文:
  1. ui &lt;- fluidPage(
  2. modalDialog(
  3. title = &quot;Clicking below to hide the modal does not work&quot;,
  4. footer = actionButton(&quot;ready&quot;, &quot;OK&quot;)
  5. )
  6. )
  7. server &lt;- function(input, output, session) {
  8. observeEvent(input$ready, {
  9. removeModal(session)
  10. })
  11. }

This does not give me any errors, it just does not work. My screen turns gray and the modal stays, unresponsive. Meanwhile, if I delete my custom button and use the default "Dismiss", then it works. I've tried with assigning ID and removing session argument, as well as many other things. I need the modal to be in UI (since package functions that I use do not work inside server) and I need observe for the "ok" button to pass arguments.

答案1

得分: 0

不确定为什么要这样做,请尝试将其放入 server.R 文件中。

  1. library(shiny)
  2. ui <- fluidPage()
  3. server <- function(input, output, session) {
  4. showModal(
  5. modalDialog(
  6. title = "单击下面的按钮以隐藏模态对话框不起作用",
  7. footer = actionButton("ready", "确定")
  8. )
  9. )
  10. observeEvent(input$ready, {
  11. removeModal()
  12. })
  13. }
  14. shinyApp(ui, server)
英文:

No sure why that is, try putting it into the server.R

  1. library(shiny)
  2. ui &lt;- fluidPage()
  3. server &lt;- function(input, output, session) {
  4. showModal(
  5. modalDialog(
  6. title = &quot;Clicking below to hide the modal does not work&quot;,
  7. footer = actionButton(&quot;ready&quot;, &quot;OK&quot;)
  8. ))
  9. observeEvent(input$ready, {
  10. removeModal()
  11. })
  12. }
  13. shinyApp(ui, server)

huangapple
  • 本文由 发表于 2023年6月16日 01:26:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76484145.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定