Shiny dynamical plot in server function module

25 views
Skip to first unread message

Shi Yu

unread,
Jun 29, 2016, 12:48:02 PM6/29/16
to Shiny - Web Framework for R
I posted this same question to stackoverflow but thought this place may have more ideas regarding to my problem.

I'd like to create dynamical tabs/plots in shiny with user input number of tabs/plots

Following Winston Chang's example https://gist.github.com/wch/5436415/

I was able to create both ui and server end functions correctly.
My server function is enclosed in a function module, so I need to use namespace to enclose the ui elememt id, but this seems cause the issue that all my dynamical plots do not show in their corresponding tabs.

For example, if my code look like this, it does NOT show the plots

      for (i in 1:input$n) {
       
local({
          my_i
<- i
          plotname
<- paste0("TabPlot", my_i) # I tried session$ns(paste0("TabPlot", my_i)), but it does not work as well.
          output
[[plotname]] <- renderDygraph({
           
return(some dygraph)
         
})
       
})
     
}



But if my code looks like this, it shows the plots

    output$TabPlot1 <- renderDygraph({
               
return(some dygraph)
             
})
    output$TabPlot2
<- renderDygraph({
               
return(some dygraph)
             
})


But certainly, in this way, I cannot make it dynamical.

Any suggestion regarding to the namespace issue? Thanks!


 

Shi Yu

unread,
Jun 29, 2016, 1:51:07 PM6/29/16
to Shiny - Web Framework for R
Problem solved by puting the for loop in a reactive environment, say
observeEvent(input$Submit, {for loop})

Reply all
Reply to author
Forward
0 new messages