I have a navbarMenu with a set of tabPanels that works fine (code block 1 below) but I want to make this dynamic so that I can add or remove tabPanels based on a condition at startup. Something along the lines of what I have in block 2 below (but that doesn't work). I'm seeing a couple of links to where people say this is not possible but it seems there must be a way. I actually only need to include or not include tabPanels on start up and don't need it to be truly dynamic.
I see an example that is close with a tabsetPanel : R Shiny - add tabPanel to tabsetPanel dynamically (with the use of renderUI). And here it says it's not possible: reactive tabPanel in a navbarMenu in Shiny
Block 1: works but not dynamic
library(shiny)
runApp(list(
ui = navbarPage(
tabPanel("a"
),
tabPanel("b"),
navbarMenu('g',
tabPanel("c"),
tabPanel("d")
)
),
server = function(input, output, session){
}
))
Block 2: I want something like this - this doesn't work
library(shiny)
runApp(list(
ui = navbarPage(
tabPanel("a"
),
tabPanel("b"),
navbarMenu('g',
uiOutput('tabs')
)
),
server = function(input, output, session){
output$tabs <- renderUI({
listoftabs <- c("c", "d")
lapply(listoftabs, tabPanel)
})
}
))