title: Shiny: dynamic UI - a loop around downloadHandler?
body: <p>I have a simple example Siny code that works fine (below). It generates a list of several tiny data frames (reactive object 'myout' in server.R). The number of the data frames is based on user's input.('NumRuns').
  My current code allows the user to download the first of these data frames - via downloadButton in ui.R and downloadHandler in server.r.
  I am wondering if it's possible to create a loop around both downloadButton and downloadHandler so that - after the analysis is run (actionButton) - the user gets as many buttons to download as there were data frames generated in 'myout'. Is it even possible?</p>
  
  <p>Or maybe it's possible to create one downloadButton that allows the user to 'pick' which data frame s/he wants to download?
  Thanks a lot for any hints - because I am not sure how to approach it!</p>
  
  <p>My code (I run it using: runApp(launch.browser = T)</p>
  
  <pre><code>### My ui.R code:
  
  shinyUI(pageWithSidebar(
  
    headerPanel("My App"),
  
    sidebarPanel(
      numericInput('NumRuns','Number of runs',value=3,min=3,max=10,step=1),
      br(),
      actionButton(inputId="goButton","Run!"),
      br(),
      br(),
      textInput("downloadData","Save My Data Frame:",value="Data Frame 1"),
      downloadButton('downloadData','Save my file!')
  
    ),
  
    mainPanel(
      tabsetPanel(
        tabPanel("Shows the 1st data frame",tableOutput("mydf"))
      )
    )
  ))
  
  
  ### My 'server.R' code:
  shinyServer(function(input,output){
  
  
    ### Creating files for displaying and downloading
  
    myout = reactive({
      if(input$goButton==0) return(NULL)
  
      nrruns=input$NumRuns
      mylist=NULL
      for(i in 1:nrruns){
        mylist[[i]]&lt;-data.frame(a=rnorm(10),b=runif(10))
        names(mylist)[i]&lt;-paste("dataframe",i,sep="")
      }
      return(mylist)
    })
  
    # Grabbing only the 1st data frame:
    output$mydf &lt;- renderTable({
      if(input$goButton==0) return(NULL)
      myout()$dataframe1
    })
  
    # Allowing to download only the 1st data frame:
    output$downloadData &lt;- downloadHandler(
      filename = function() { paste(input$downloadData, " ",Sys.Date(),".csv",sep="") },
      content = function(file) {
        write.csv(myout()$dataframe1,file,row.names=F)
      }
    )
  
  })
  </code></pre>