【发布时间】:2021-03-17 23:30:39
【问题描述】:
我希望在闪亮的应用程序中弹出 modal,这取决于用户在模式中的操作, 它会显示或隐藏某些字段。
例如,Modal 包含一个按钮,当按下该按钮时,另一个按钮会出现\消失。
遗憾的是,虽然 observeEvent 检测到 hide\show 按钮的变化,shinyjs::toggle(), shinyjs::hide() 和 shinyjs::show() 无法工作
示例脚本:
library(shiny)
ui <- fluidPage(
actionButton("show_modal", "show modal"),
)
server <- function(input, output) {
observeEvent(input$show_modal, {
showModal(
modalDialog(footer = NULL,easyClose = T,
tagList(
fluidRow(
box(status = "primary", width = 6, style = "direction: ltr",
actionButton("toggle_btn", "show or hide second button")
)),
fluidRow(
box(status = "success", width = 6, style = "direction: ltr",
actionButton("box_btn", "Box!")
))
)
))
})
observeEvent(input$toggle_btn, {
shinyjs::toggle("box_btn")
cat("\npresentation button pressed\n")
})
}
shinyApp(ui, server)
【问题讨论】:
标签: r shiny modal-dialog hide show