title: R Shiny loop to display multiple plots
body: <p>Ok I have code that you can run below. I am trying to modify this code:</p>
  
  <p><a href="https://gist.github.com/wch/5436415/" rel="nofollow">https://gist.github.com/wch/5436415/</a></p>
  
  <p>so that max_plots is dynamically set using input from the UI. The input from the UI is dynamic as well.</p>
  
  <p>Here is my UI.R:</p>
  
  <pre><code>shinyUI(pageWithSidebar(
    headerPanel("Dynamic number of plots"),
    sidebarPanel(
      selectInput("Desk", "Desk:" ,  c("A","B")),
     uiOutput("choose_Product"),
  uiOutput("choose_File1"),
  uiOutput("choose_Term1"),
  sliderInput("n", "Number of plots", value=1, min=1, max=5)
    ),
  
    mainPanel(
      # This is the dynamic UI for the plots
      h3("Heading 1"),
      uiOutput("plots"),
     h3("Heading 2")
    )
  ))
  </code></pre>
  
  <p>Here is my Server.R:</p>
  
  <pre><code>shinyServer(function(input, output) {
  
    output$choose_Product &lt;- renderUI({
      selectInput("Product", "Product:", as.list( c("Product1","Product2","Product3")))
    })
  
    output$choose_File1 &lt;- renderUI({
  selectInput("File1", "File1:", as.list(c("File1","File2","File3")))
    })
  
  # Insert the right number of plot output objects into the web page
  
    output$plots &lt;- renderUI({
        plot_output_list &lt;- lapply(1:input$n, function(i) {
          plotname &lt;- paste("plot", i, sep="")
          plotOutput(plotname, height = 280, width = 250)
        })
  
        # Convert the list to a tagList - this is necessary for the list of items
        # to display properly.
        do.call(tagList, plot_output_list)
    })##End outputplots
  
    PrintPlots&lt;- reactive({
  ## I need max_plots to be set as the length of the Vector returns from getAugmentedTerms()
  max_plots&lt;-length(getAugmentedTerms(input$Desk, input$Product, input$File1))
  
  # Call renderPlot for each one. Plots are only actually generated when they
  # are visible on the web page.
  
  for (i in 1:max_plots) {
    # Need local so that each item gets its own number. Without it, the value
    # of i in the renderPlot() will be the same across all instances, because
    # of when the expression is evaluated.
    local({
          my_i &lt;- i
          plotname &lt;- paste("plot", my_i, sep="")
  
          output[[plotname]] &lt;- renderPlot({
             plot(1:my_i, 1:my_i,
             xlim = c(1, max_plots),
                 ylim = c(1, max_plots),
                 main = paste("1:", my_i, ". n is ", input$n, sep = "") )
          })
        })
      }##### End FoR Loop
    })# END OF PRINT PLOTS
  })# END OF ENERYTHING
  </code></pre>
  
  <p>Here is my global.R:</p>
  
  <pre><code>getAugmentedTerms&lt;-function(desk, product, file)
  {
     # this function takes 3 inputs from the UI and returns a vector
     # for simplicity I am just returning a 2 element vector
     d&lt;-c(1,2)
     return d
  }
  </code></pre>
  
  <p>Here is code to run it:</p>
  
  <pre><code>library(shiny)
  runApp("C:/Users/user/Desktop/R Projects/TestDynamicPlot")
  </code></pre>
  
  <p>When you run this you can see space is created like there are being plots output but the output is blank.  Any ideas? Thank you!</p>