Hi,
I'm new to using Shiny modules, and am having difficulty getting updateTabsetPanel to work within one of these. My use case is a large app with three unconnected tabs (using TabPanels), which I am compartmentalising into modules.
The internal structure of one of these tabs also uses TabPanels, with a button which can be pressed to navigate to a hidden tab.
Here is a minimal reprex of the code using modules which isn't working:
library(shiny)
demoUI <- function(id){
tabsetPanel(
id = "navigation",
type = "hidden",
tabPanelBody(
value = "main_panel",
actionButton(NS(id, "info_nav"), "Get info") # Pressing this button should take user to info_panel
),
tabPanelBody(
value = "info_panel",
actionButton(NS(id, "main_nav"), "Back to main page")
)
)
}
demoServer <- function(id){
moduleServer(id, function(input, output, session) {
observeEvent(input$info_nav, {
updateTabsetPanel(
inputId = "navigation",
selected = "info_panel"
)
})
observeEvent(input$main_nav, {
updateTabsetPanel(
inputId = "navigation",
selected = "main_panel"
)
})
})
}
ui <- fluidPage(
demoUI("test")
)
server <- function(input, output, session) {
demoServer("test")
}
shinyApp(ui, server)
This is version not using modules which does work:
library(shiny)
ui <- fluidPage(
tabsetPanel(
id = "navigation",
type = "hidden",
tabPanelBody(
value = "main_panel",
actionButton("info_nav", "Get info")
),
tabPanelBody(
value = "info_panel",
actionButton("main_nav", "Back to main page")
)
)
)
server <- function(input, output, session) {
observeEvent(input$info_nav, {
updateTabsetPanel(
inputId = "navigation",
selected = "info_panel"
)
})
observeEvent(input$main_nav, {
updateTabsetPanel(
inputId = "navigation",
selected = "main_panel"
)
})
}
shinyApp(ui, server)
What am I doing wrong in the modules implementation?