1

I am looking to allow the user to enter the quantity of files they are interested in uploading, and then having the UI react to give that many file input buttons.

I am not certain how to do this. Even once this is completed, I am not certain how best to handle this dynamic amount of variables.

#ui.R

  shinyUI(fluidPage(
    titlePanel("Upload your files"),
    fluidRow(

      column(3, wellPanel(
        numericInput("user_num_2", 
                     label = h4("Number of Old Files"), 
                     value = 1)
      )),

      column(4, wellPanel(
        # This outputs the dynamic UI component
        uiOutput("ui1")
      ))
    ),
    fluidRow(

      column(3, wellPanel(
        numericInput("user_num_2", 
                     label = h4("Number of New Files"), 
                     value = 1)
      )),


      column(4, wellPanel(
        # This outputs the dynamic UI component
        uiOutput("ui2")
      ))
    ),
    fluidRow(

      column(3, wellPanel(

        selectInput("input_type", 
                    label = h4("Geography Assignment"), 
                    c("Zip", "County", "Zip-County", "Custom Assignment"
                    )
        )
      ))
    )
  ))

So a user can enter how many file upload buttons they want. The idea is to merge them all together. The multiple option would not work because these files could be in different locations.

screen shot

Reck
  • 245
  • 1
  • 3
  • 9
  • you should include a reproducible example of what your are trying to achieve. – MLavoie Dec 14 '15 at 19:02
  • A minimal shiny code would be useful but the question is clear enough IMO. – Dason Dec 14 '15 at 19:34
  • @MLavoie I hope you don't find this argumentative, but if I was capable of doing that, I would not need to ask for help. – Reck Dec 14 '15 at 19:40
  • 1
    Not sure how big your files are, but quickest solution i can think of is to put them all in the same location and use the multiple argument. Much cleaner than having multiple variable fileInputs... – Raad Dec 14 '15 at 22:19
  • @NBATrends that has worked in the past, though this particular project would not permit that. – Reck Dec 15 '15 at 16:38

1 Answers1

0

Ok I hope you like this. Idea came from this post: Shiny R renderPrint in loop usinf RenderUI only update the output

You can easily store the objects created from each of the file inputs in a list to be used for further analysis.

Server

shinyServer(function(input, output, session) {
  output$fileInputs=renderUI({
    html_ui = " "
    for (i in 1:input$nfiles){
      html_ui <- paste0(html_ui, fileInput(paste0("file",i), label=paste0("file",i)))
    }
    HTML(html_ui)
  })

})

UI

shinyUI(pageWithSidebar(
  headerPanel('Variable files'),
  sidebarPanel(
    numericInput("nfiles", "number of files", value = 2, min = 1, step = 1),
    uiOutput("fileInputs")
  ),
  mainPanel()
))

Some explanation, shiny operates through HTML. If you run the line of code below in the console you will see the logic behind creating the object html_ui that can hold a variable number of these HTML elements.

fileInput(paste0("file",1), label=paste0("file",1))

# <div class="form-group shiny-input-container">
#   <label>file1</label>
#   <input id="file1" name="file1" type="file"/>
#     <div id="file1_progress" class="progress progress-striped active shiny-file-input-progress">
#       <div class="progress-bar"></div>
#   </div>
# </div>
Community
  • 1
  • 1
Raad
  • 2,675
  • 1
  • 13
  • 26