Switch beetweeen tabItems


#1

I want to use action buttons to navigate to differentes tabs of the sidebar menu in a shiny app, but when I click the button nothings happen.

Here is the code

header <- dashboardHeader(
  title = "Button Test"
)

sidebar <- dashboardSidebar(
  #sidebarmenu
  sidebarMenu(id ="tabs",
              menuItem("Introduction", tabName = "intro", icon = icon("edit") ),
              menuItem("Data Input", tabName = "data", icon = icon("server")),
              menuItem("Quality Contol", tabName = "qc", icon = icon("braille")

body <- dashboardBody(
  
  #tabitems
  tabItems(
    
    ##################Intro tab#################
    tabItem(tabName = "intro",
            h1("Introduction")),
   tabItem(tabName = "data",
            h1("data"),
   actionButton("btn_switchtab", "Go to QC", class ="btn-info")),
   tabItem(tabName = "qcbn,
                h1("quality control"))

ui <- dashboardPage(header, sidebar, body)

server <- function(input, output){

oserveEvent(input$btn_switchtab, {
    newtab <- switch(input$tabs,
                     "data" = "qcbn",
                     "qcbn"   = "data"
    )
    updateTabItems(session, "tabs", newtab)
  })

}

# Run the application 
shinyApp(ui = ui, server = server)


#2

Hi Bort, that doesn't seem to be a working reproducible example.

Ideally, you'd give us a reproducible example (reprex) of your issue that folks can copy and use as a starting point. A reprex makes it much easier for others to understand your issue and figure out how to help. A lack of a reprex just makes it much less likely others will reply.