Search code examples
rshinytabpanel

Use renderUI to insert additional tabPanel in R Shiny


I am trying to append a tab created by renderUI to an existing tab set. Minimal example:

ui <- fluidPage(sidebarLayout(sidebarPanel(),
                              mainPanel(tabsetPanel(
                                tabPanel("static_tab"),
                                uiOutput('ui_tab')
                              ))))
server <- function(input, output) {
  output$ui_tab <- renderUI({
    tabPanel("render_tab", p('it worked'))
  })
}
shinyApp(ui = ui, server = server)

I can get an an entire tabsetPanel to render, but not an individual tab in an existing tabsetPanel.


Solution

  • You can use insertTab or appendTab:

    ui <- fluidPage(sidebarLayout(sidebarPanel(),
                                  mainPanel(
                                    tabsetPanel(id = "myTabsetPanel",
                                                tabPanel("static_tab", tabName = "static_tab"))
                                  )))
    server <- function(input, output) {
      appendTab(inputId = "myTabsetPanel",
                tabPanel("render_tab", p('it worked')))
    }
    shinyApp(ui = ui, server = server)
    

    renderUI won't work as it creates a div tag - however, you need to create a li tag.