r - In Shiny, how to make tabs appear one at a time without javascript, etc -


i use set of if , else statements select tabsetpanel use. idea have new tabs appear user performs prerequisite tasks. created seems try that, existing tabs reloaded, resetting state of tab, , therefore removing tab added. in example, can see second tab flash existence , disappear. how can make input in each tab persist upon recreation of tabsetpanel? read response a similar question, not familiar javascript (or whatever code inside tags$script in answer), i'd solution requires r code.

the app available on shinyapps.

the code pasted below, , available on github.

ui.r

library(shiny) shinyui(pagewithsidebar(   headerpanel("subset data before analyzing"),   sidebarpanel(),   mainpanel(uioutput("panels")) )) 

server.r

library(shiny) shinyserver(function(input, output) {      #this data   d1 = data.frame(     student = c("abe","bill","clare","abe","bill","clare"),     class = c("ela","ela","ela","math","math","math"),     grade = c(71,72,73,74,75,76))    # pulls list of unique names student column of data , creates checklist   output$studentchecklist <- renderui({     if(is.null(d1)){return ()     } else taglist(       checkboxgroupinput(inputid = "selectedstudents",                           label = "which students select?",                           choices = unique(as.character(d1$student)))     )   })    #this pulls list of unique names class column of data , creates checklist   output$classchecklist <- renderui({     if(is.null(d1)){return ()     } else taglist(       checkboxgroupinput(inputid = "selectedclasses",                           label = "which classes select?",                           choices = unique(as.character(d1$class)))     )   })    # generates table of data subsetted checklist selections   output$summary = rendertable({     if(is.null(d1)){return ()     } else {       d3 = d1[which(as.character(d1$student) %in% input$selectedstudents),]       d3 = d3[which(as.character(d3$class) %in% input$selectedclasses),]       return(d3)     }   })      # these definitions individual panels   p1 = reactive(tabpanel("pick students",uioutput("studentchecklist")))   p2 = reactive(tabpanel("pick classes",uioutput("classchecklist")))   p3 = reactive(tabpanel("summary",tableoutput("summary")))    # generates actual panel layout   output$panels = renderui({     taglist(       if(is.null(d1)){return()       } else if (length(input$selectedstudents)==0){tabsetpanel(p1())       } else if (length(input$selectedclasses)==0){tabsetpanel(p1(),p2())       } else tabsetpanel(p1(),p2(),p3())       )   }) }) 

i found solution problem. involves few components.

first, had create new version of tabsetpanel function (which called tabsetpanel2. same tabsetpanel except drops tabpanel objects null. way, tabpanel objects not supposed appear can set null, , call tabsetpanel doesn't have change.

second, had create reactive objects held selections made user on each widget resides on tabpanel, , set selected parameter of widget to reactive object. way, when tabsetpanel2 rebuilt, loads entered info.

third, had create reactive object hold name of selected tab. way, when tabsetpanel2 rebuilt, automatically goes tab user on.

all of code can found in github repository mentioned in question.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -