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

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

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中(因为我使用的包函数在服务器中不起作用),我需要观察 "确定" 按钮以传递参数。

英文:
    ui &lt;- fluidPage(
modalDialog(
    title = &quot;Clicking below to hide the modal does not work&quot;,
    footer = actionButton(&quot;ready&quot;, &quot;OK&quot;)
)
)
server &lt;- function(input, output, session) {
  observeEvent(input$ready, {
    removeModal(session)
  })
}

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 文件中。

library(shiny)

ui <- fluidPage()
server <- function(input, output, session) {

  showModal(
    modalDialog(
      title = "单击下面的按钮以隐藏模态对话框不起作用",
      footer = actionButton("ready", "确定")
    )
  )

  observeEvent(input$ready, {
    removeModal()
  })
}

shinyApp(ui, server)
英文:

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

library(shiny)

ui &lt;- fluidPage()
server &lt;- function(input, output, session) {
  
  showModal(
    modalDialog(
    title = &quot;Clicking below to hide the modal does not work&quot;,
    footer = actionButton(&quot;ready&quot;, &quot;OK&quot;)
  ))
  
  observeEvent(input$ready, {
    removeModal()
  })
}

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:

确定