我有一个简单的闪亮机制问题,我不明白为什么以及如何回答它。 我有一个应用程序,其中observeEvent 操作位于模块服务器内。该服务器与 tabPanel 关联。 我的问题是:如果我单击按钮,关闭模式,更改面板,然后返回首页,模式会再次显示。如何防止这种行为?我应该“重置”actionButton 值还是反应性错误?
library(shiny)
mod_test_ui <- function(id){
ns <- NS(id)
tagList(
actionButton(ns("click_me"), "Click")
)
}
mod_results_server <- function(id){
moduleServer(id, function(input, output, session){
ns <- session$ns
observeEvent(input$click_me, {
showModal(modalDialog(id = "mymodalstudy", "Here is a modal"))
})
})
}
ui <- bootstrapPage(
tabsetPanel(id = "mytab",
tabPanel("Home", mod_test_ui("Test")),
tabPanel("Other", p("Other content"))))
server <- function(input, output) {
observeEvent(input$mytab,{
if(input$mytab == "Home") {
mod_results_server("Test")
}
})
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)
moduleServer()
必须创建一次。
library(shiny)
mod_test_ui <- function(id){
ns <- NS(id)
tagList(
actionButton(ns("click_me"), "Click")
)
}
mod_results_server <- function(id){
moduleServer(id, function(input, output, session){
ns <- session$ns
observeEvent(input$click_me, {
showModal(modalDialog(id = "mymodalstudy", "Here is a modal"))
})
})
}
ui <- bootstrapPage(
tabsetPanel(id = "mytab",
tabPanel("Home", mod_test_ui("Test")),
tabPanel("Other", p("Other content")),
selected ="Home"
)
)
server <- function(input, output) {
observeEvent(input$mytab,{
# at the beginning input$mytab is NULL
if (ifelse (is.null(input$mytab),"Home",input$mytab) == "Home") {
mod_results_server("Test")
}
},
# at the beginning input$mytab is NULL
# create once
ignoreNULL = FALSE, once=TRUE) # <-----
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)