Search code examples
rshinyaction-button

Is there any way for an actionButton() to navigate to another tab within a R Shiny application?


I have multiple tabs within my R Shiny app and haven't discovered a way to have my action button navigate to another tab.

The first tab ends with a "submit info" action button, and the goal is to have the "results" tab open after the user submits. If anyone might have some pseudo code that could make this happen, anything would be extremely helpful.


Solution

  • Hi you can use updateTabsetPanel to do that, you have to put an id to your tabsetPanel (if you use a tabsetPanel) and add session to your server function :

    library("shiny")
    ui <- fluidPage(
      tabsetPanel(
        id = "tabs",
        tabPanel(
          title = "params",
          actionButton(inputId = "submitInfo", label = "submit info")
        ),
        tabPanel(
          title = "result",
          "result"
        )
      )
    )
    server <- function(input, output, session){
      observeEvent(input$submitInfo, {
        updateTabsetPanel(session = session, inputId = "tabs", selected = "result")
      })
    }
    shinyApp(ui = ui, server = server)
    

    If you use a navbarPage or shinydashboard it works the same way