-
I am struggling in using As an example, the following simple Shiny app works: # Inserting and removing
ui <- page_fluid(
actionButton("add", "Add 'Dynamic' tab"),
actionButton("remove", "Remove 'Foo' tab"),
navset_card_pill(
id = "tabs",
nav_panel("Hello", "hello"),
nav_panel("Foo", "foo"),
nav_panel("Bar", "bar tab")
)
)
server <- function(input, output) {
observeEvent(input$add, {
nav_insert(
"tabs",
target = "Bar",
select = TRUE,
nav_panel("Dynamic", "Dynamically added content")
)
})
observeEvent(input$remove, {
nav_remove("tabs", target = "Foo")
})
}
shinyApp(ui, server) But once I put the UI into a module, I am lost. This would be the main app: ui <- page_fluid(
mod_nav_tabs_ui("main_tabs")
)
server <- function(input, output, session) {
mod_nav_tabs_server("main_tabs")
}
shinyApp(ui, server) and this is the module, to be put under mod_nav_tabs_ui <- function(id) {
ns <- NS(id)
tagList(
actionButton(ns("add"), "Add 'Dynamic' tab"),
actionButton(ns("remove"), "Remove 'Foo' tab"),
navset_card_pill(
id = ns("tabs"),
nav_panel("Hello", "hello"),
nav_panel("Foo", "foo"),
nav_panel("Bar", "bar tab")
)
)
}
mod_nav_tabs_server <- function(id) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
observeEvent(input$add, {
nav_insert(
ns("tabs"),
target = "Bar",
select = TRUE,
nav_panel("Dynamic", "Dynamically added content")
)
})
observeEvent(input$remove, {
nav_remove(ns("tabs"), target = "Foo")
})
})
} What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
cpsievert
Jul 23, 2025
Replies: 1 comment 1 reply
-
I'm pretty sure you can just remove the |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
fzenoni
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm pretty sure you can just remove the
ns()
calls inmod_nav_tabs_server
?