rstudio / shinydashboard

Shiny Dashboarding framework
https://rstudio.github.io/shinydashboard/
Other
893 stars 298 forks source link

updateTabsetPanel does not work with tabBox #354

Open tomicapretto opened 3 years ago

tomicapretto commented 3 years ago

I want to have a button inside a tabPanel within a tabBox that when clicked switches to another tabPanel within the same tabBox.

None of the approaches I tried worked. Also, I couldn't find much documentation on how this is expected to work.

I'm using shiny 1.5.0 and shinydashboard 0.7.1

Concisely, is this the correct approach? Is it possible to do what I am trying to do? Thank you!

  library(shiny)
  library(shinydashboard)

  ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
      fluidRow(
        tabBox(
          id = "tabs",
          height = "auto",
          width = 12,
          title = "",
          tabPanel(
            title = "Title1",
            value = "one",
            actionButton("move", "Move!")
          ),

          tabPanel(
            title = "Title2",
            value = "two",
            actionButton("moveback", "Move back!")
          )
        )
      )
    )
  )

  server <- function(input, output, session) {
    observeEvent(input$move, {
      print("move!")
      updateTabsetPanel(session, "tabs", "one")
    })
    observeEvent(input$moveback, {
      print("moveback!")
      updateTabsetPanel(session, "tabs", "two")
    })
    observeEvent(input$tabs, print(input$tabs))
  }

  shinyApp(ui, server)