Hi,
Shiny has some built in ways of hiding and showing tabs. Take a look at this example:
library(shiny)
ui <- fluidPage(
tabsetPanel(id = "tabSet",
tabPanel(value = "tab1", title = "Tab 1", tags$h1("TAB 1 content ..."),
actionButton("toggleTab", "Show tab 2")),
tabPanel(value = "tab2", title = "Tab 2", tags$h1("TAB 2 content ...")),
tabPanel(value = "tab3", title = "Tab 3", tags$h1("TAB 3 content ..."))
)
)
server <- function(input, output, session) {
hideTab("tabSet", "tab2")
observeEvent(input$toggleTab, {
if(input$toggleTab %% 2 == 0){
hideTab("tabSet", "tab2")
updateActionButton(session, "toggleTab", label = "Show tab 2")
} else {
showTab("tabSet", "tab2")
updateActionButton(session, "toggleTab", label = "Hide tab 2")
}
})
}
shinyApp(ui, server)
You need to give every tabsetPanel an ID, and then each tab a value. You can then hide or show a tab with the hideTab() or showTab() function respectively, where you refer to the tabset id and the panel value.
Note that we start with tab 2 in a hidden state by putting hideTab("tabSet", "tab2") at the start of the server code.
In the example, a button will hide or show the tab depending on its state. I used the counter that comes with the button to keep track of the tab being in a hidden state or not.
Hope this helps,
PJ