Home > Software engineering >  In R/Shiny why using map to create tabpanels is not working?
In R/Shiny why using map to create tabpanels is not working?

Time:11-19

I want to achieve the same result of:

tabsetPanel(

        # Hide the tab values.
        # Can only switch tabs by using `updateTabsetPanel()`

        tabPanel(1, "Panel 1 content"),
        tabPanel(2, "Panel 2 content"),
        tabPanel(3, "Panel 3 content")
      )

using this code bellow. Why it is not working?

 tabsetPanel(

       map(1:3,~  tabPanel(.x,title = paste0("Panel ",.x," content"))

      ))

Thanks

CodePudding user response:

map returns a list in a structure that tabsetPanel does not fully recognize. If you wrap everything in a call to do.call it should work.

do.call(tabsetPanel, map(1:3,~  tabPanel(.x,title = paste0("Panel ",.x," content"))))
  • Related