xyn3rgy
xyn3rgy

Reputation: 117

For loops (lapply) navbarPage within in Ui.R

I have a tabPanel repeated using a for loop as the contents are repeated.

The problem is that most likely incorrect placement of the for loop. Results in no-sub menu being created with random text being displayed "tab-1810-1"

ui.R

library(shiny)
shinyUI(navbarPage("Nav Bar Title", 
  navbarMenu("Nav Bar Sub-title",
    lapply(1:2, function(v) {
      tabPanel(criteria[v],
        fluidRow(
        )
      ) 
    })
  ) 
))

Illustration of the sub-menu:

Upvotes: 1

Views: 703

Answers (1)

NicE
NicE

Reputation: 21435

You need to use do.call in this case to pass all the tabs to the navbarMenu:

library(shiny)
criteria <- c("test1","test2")
tabs <- lapply(1:2, function(v) {
  tabPanel(criteria[v],
           fluidRow(
           )
  ) 
})

ui <-shinyUI(navbarPage("Nav Bar Title", 
                   do.call(navbarMenu,c("title",tabs))
                   ) 
)

server <- function(input, output) {}
shinyApp(ui,server)

Upvotes: 2

Related Questions