Home > Net >  In Shiny/R how to create tabpanels inside tabsetpanels using map functions
In Shiny/R how to create tabpanels inside tabsetpanels using map functions

Time:07-19

I need to create a panels inside a tabset in shiny using map functions .

The output that I need is one tabsetPanels with 3 tab panels This is the app:

library(shiny)

ui <- fluidPage(


  tabsetPanel('one',
              map(1:3,
                 ~ tabPanel(paste0("panel_",.x))
                  )
              )
)


server <- function(input, output, session) {

}

shinyApp(ui, server)

What am I doing wrong?

CodePudding user response:

The map function returns a list. But tabsetPanel does not expect a list of tabPanels. It rather expects that each panel is an individual parameter.

You can get around this using do.call. WIth do.call you can call any function and pass it's argument as list.

See below:

library(shiny)

ui <- fluidPage(
  do.call(
    tabsetPanel,
      map(1:3, ~ tabPanel(paste0("panel_",.x)))
    )
)


server <- function(input, output, session) {

}

shinyApp(ui, server)
  • Related