I\'m making a ShinyDashboard program and I have some troubles in finding a way to make a loop in the dashboardBody to catch MenuItems. This is a simple example of what I\'m tryi
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)
})