I have a shiny application built with navbar.
I would like to be able to retrieve which tab and sub-tab are active? That is, which tabPanel and sub-tabPanel are active ?
In the console I can find out which 1st level tab is active. But I don't know how to retrieve the 2nd level tabs.
library("shiny")
ui = navbarPage(title = "Navbar example",
id = "navbar",
tabPanel(title = "tab 1",
tabsetPanel(id = "id1",
tabPanel(title = "A",
),
tabPanel(title = "B",
)
)),
tabPanel(title = "tab 2",
tabsetPanel(id = "id2",
tabPanel(title = "C",
),
tabPanel(title = "D",
),
tabPanel(title = "E",
)
))
)
server = shinyServer(function(input, output) {
observe({
print(paste0("You are viewing tab \"", input$navbar))
})
})
shinyApp(ui, server)
Ideally, I'd like to have for example :
- tab 1 selected and
- sub-tab B selected
I'm not interested in doing input$id1 or input$id2.
I want the information without having to specify which main tab is already selected
I can't find any way to avoid using
input$id1but this method at least automates it: