I have a Shiny app with several tabPanels within a navbarPage.
ui<-shinyUI(
navbarPage(
theme = "cyborgBootstrap.css",
"Shiny panel append",
tabPanel(
"First Panel",
strong("panel 1")
),
tabPanel(
"Second Panel",
strong("panel 1")
),
tabPanel(
"Third Panel",
strong("panel 1")
)
)
)
When the app loads, "First Panel" will be active. I would like to be able to add some server functions that toggle the panels when certain tasks complete. How could I toggle between panels programatically?
library(shiny)
ui <- navbarPage(title = "updateNavbarPage", id = "tabs", tabPanel(title = "First Panel", value = "panel1", strong("Panel 1"), hr(), actionButton("go1to2", "Go to 2"), actionButton("go1to3", "Go to 3") ), tabPanel(title = "Second Panel", value = "panel2", strong("Panel 2"), hr(), actionButton("go2to1", "Go to 1"), actionButton("go2to3", "Go to 3") ), tabPanel(title = "Third Panel", value = "panel3", strong("Panel 3"), hr(), actionButton("go3to1", "Go to 1"), actionButton("go3to2", "Go to 2") ))
server <- function(input, output, session) { observeEvent(c(input$go2to1, input$go3to1), { updateNavbarPage(session, "tabs", selected = "panel1") }, ignoreInit = TRUE) observeEvent(c(input$go1to2, input$go3to2), { updateNavbarPage(session, "tabs", selected = "panel2") }, ignoreInit = TRUE) observeEvent(c(input$go1to3, input$go2to3), { updateNavbarPage(session, "tabs", selected = "panel3") }, ignoreInit = TRUE)}
shinyApp(ui, server)