0

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!

-------------Update-------------------

I've put the entire for loop in a reactive environment, say observerEvent(input$Submit, {for loop}) and it works.

athlonshi
  • 1,711
  • 1
  • 19
  • 23
  • Will be hard to help without more code. Is the for loop just in the middle of a module or is it in a `reactive` or `observe` call? – Carl Jun 29 '16 at 17:33
  • Thanks. Sorry, the code is very long and it is hard to come up with a shorter reproducible code. The for loop is in a server function module, and the module is called in server.R by callModule. – athlonshi Jun 29 '16 at 17:36
  • What happens if you wrap the for loop in `reactive`? – Carl Jun 29 '16 at 18:09
  • Here is a link to my answer to another question but which may help. http://stackoverflow.com/questions/35914055/how-to-create-shiny-r-dynamic-rendertable-with-a-number-of-tables-determined-by/35943224#35943224 – Xiongbing Jin Jun 29 '16 at 18:28
  • I think wrap into reactive will also work but I have not tried. Because the for loop code has side effect, I do not want to include reactive which supposely should return something. Also, I do need to observe an action in order to trigger the ploting. – athlonshi Jun 29 '16 at 20:11

0 Answers0