【发布时间】:2019-02-18 23:57:40
【问题描述】:
在 Shiny 模块中调用 updateTabsetPanel 时遇到问题,不用也可以正常工作。
library(shiny)
mod_ui <- function(id){
ns <- NS(id)
tagList(
actionButton(ns("back"), "back")
)
}
mod <- function(input, output, session){
observeEvent(input$back, {
print("Button click, go back to home tab")
updateTabsetPanel(session = session, inputId = "tabs", selected = "home")
})
}
ui <- navbarPage(
"example",
id = "tabs",
tabPanel(
"home",
h4("updateTabsetPanel does not work with modules"),
h5("But the button below does"),
actionButton("switch", "switch")
),
tabPanel(
"secondtab",
mod_ui("second")
)
)
server <- function(input, output, session){
callModule(mod, "second")
observeEvent(input$switch, {
updateTabsetPanel(session = session, inputId = "tabs", selected = "secondtab")
})
}
shinyApp(ui, server)
【问题讨论】: