英文:
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 <- fluidPage(
modalDialog(
title = "Clicking below to hide the modal does not work",
footer = actionButton("ready", "OK")
)
)
server <- 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 <- fluidPage()
server <- function(input, output, session) {
showModal(
modalDialog(
title = "Clicking below to hide the modal does not work",
footer = actionButton("ready", "OK")
))
observeEvent(input$ready, {
removeModal()
})
}
shinyApp(ui, server)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论