Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make dynamic shiny tabs with their own content?

So I've looked at the following links to make dynamic tabs when I perform an action and to create tabs with their own sidebars, but I can't seem to put 2 and 2 together.

R Shiny - add tabPanel to tabsetPanel dynamically (with the use of renderUI)

Are tabs with their own sidebars and mainPanels possible in shiny?

Does anyone know how to access the tabs after you dynamically create them? Also, is the renderUI example bad in this case because it creates a new list of headers with every action?

like image 399
Froblinkin Avatar asked Jul 29 '15 14:07

Froblinkin


1 Answers

I would like to thank all the good people over at stackoverflow for aiding me in solving this problem; this is the most supportive site for programming beginners out there.

UI:

library(shiny)
shinyUI(navbarPage("TiGr",

               tabPanel("File Input Page",
                        fluidPage("Input")),

               tabPanel("Summary Statistics and Plots",
                        fluidPage("Statistics")),

               tabPanel("Time Clusters",
                        fluidPage("cluster"),
                        actionButton("subClust", label = "Create Subcluster"),
                        uiOutput("tabs"),
                        conditionalPanel(condition="input.level==1",
                                         helpText("test work plz")
                        ), 
                        conditionalPanel(condition="input.level==5",
                                         helpText("hohoho")
                        )
               )
))

Server:

library(shiny)

shinyServer(function(input, output,session) {
  output$tabs=renderUI({

Tabs<-as.list(rep(0,input$subClust+1))
for (i in 0:length(Tabs)){
  Tabs[i]=lapply(paste("Layer",i,sep=" "),tabPanel,value=i)
}

#Tabs <- lapply(paste("Layer",0:input$subClust,sep=" "), tabPanel)
do.call(tabsetPanel,c(Tabs,id="level"))
})
}
)
like image 122
Froblinkin Avatar answered Nov 02 '22 00:11

Froblinkin