Below I display 2 attempts.I have a shiny dashboard with tabPanels. I would like to create the tabPanels of the tabPanel Data automatically based on the Uni dataframe. In my first try below those tabPanels are commented out inorder to make clear what I mean.
Uni<-data.frame(NAME=c("A","B","C"))
# app.R ##
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
dbHeader <- dashboardHeaderPlus(
title = "Tabs"
)
ui <- dashboardPagePlus(
dbHeader,
dashboardSidebar(),
dashboardBody(
useShinyjs(),
tags$hr(),
tabsetPanel(
id ="tabA",
type = "tabs",
tabPanel("Front",icon = icon("accusoft")),
tabPanel("Data", icon = icon("table"),
tabsetPanel(
id ="tabA",
type = "tabs",
for(i in 1:nrow(Uni)){
tabPanel(
paste0(Uni[i,1])
,icon = icon("table"))
}
#tabPanel("A",icon = icon("table")),
#tabPanel("B", icon = icon("table")),
#tabPanel("C", icon = icon("table"))
)
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
and my 2nd attempt:
# app.R ##
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
dbHeader <- dashboardHeaderPlus(
title = "Tabs"
)
ui <- dashboardPagePlus(
dbHeader,
dashboardSidebar(),
dashboardBody(
useShinyjs(),
tags$hr(),
tabsetPanel(
id ="tabA",
type = "tabs",
tabPanel("Front",icon = icon("accusoft")),
tabPanel("Data", icon = icon("table"),
tags$hr(),
tabsetPanel(
id ="tabA",
type = "tabs",
uiOutput("panels")
#tabPanel("A",icon = icon("table")),
#tabPanel("B", icon = icon("table")),
#tabPanel("C", icon = icon("table"))
)
)
)
)
)
server <- function(input, output) {
output$panels <- renderUI({
pan = lapply(1:length(Uni), function(i)
tabPanel(Uni[i,1],icon = icon("table")))
do.call(tabBox,pan)
})
}
shinyApp(ui = ui, server = server)