Search code examples
rshinytabpanel

Remove active tabpanel with button in Shiny App


Hi everyone I would love to know if it's possible to remove the current active tabPanel on a shiny app :

This is my code:

  # server
  observeEvent(input$removeTab, priority = 20, {
     removeTab(inputId="sortTab", target=input$ACTIVE_TAB)
  })

  # ui
  actionButton("removeTab", "Remove current tab")

Thanks a lot for your help!


Solution

  • Here is the answer. If the tabPanel that we desire to remove is encapsulated in a TabsetPanel, for example in a :

    TabsetPanel(id='sortTab', Tabpanel(), Tabpanel() )

    We juste have to respecify the TabSetPanel id with the input argument on the target :

      # server
      observeEvent(input$removeTab, priority = 20, {
         removeTab(inputId="sortTab", target=input$sortTab)
      })
    
      # ui
      actionButton("removeTab", "Remove current tab")