How to make a function in a for loop or lapply loop in a tabItem dashboard shiny

不羁的心 提交于 2019-12-02 07:13:16

The problem in your code is, that you try to use a list of tabItem objects as an argument for tabItems, but this is invalid according to the documentation of tabItems.

tabItems(...)

... Items to put in the container. Each item should be a tabItem.

do.call can be used to resolve this issue. Basically, do.call operates as follows.

add <- function(x, y){x + y}
do.call(add, list(4, 3)) # same as add(4, 3)
## 7

So you basically want to use the list returned from lapply as the second argument to do.call while the first argument is the function to call (tabItems).

output$test_UI <- renderUI ({
  items <- c(
    list(tabItem(tabName = "menu1_tab", uiOutput("menu1_UI"))),
    lapply(1:5, function(i){
      tabItem(tabName = VecNames[i], uiOutput(paste0("Menu",i)))        
    })
  )
  do.call(tabItems, items)
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!