thomasp85/shinyFiles

using the same button to choose multiple files in different directories

olechnwin opened this issue · 0 comments

Hi,

I am trying to use the same button to choose multiple files that are in different directories. I was able to return the paths chosen when the button is clicked once. But when the button is clicked the second time, I tried to concat the paths to the existing one but it didn't work.

Here is a simple example of what I'm trying to do:

library(shinyFiles)

ui <- fluidPage(
 
 titlePanel("File Browser"),
 
 sidebarLayout(
  sidebarPanel(
   
   shinyFilesButton('files', label = 'Select', title = 'Please select a 
                       file', multiple = TRUE),
   verbatimTextOutput("filechosen")
  ),
  
  mainPanel(
  )
 )
)

r1.lst <- NULL
server <- function(input, output) {
 
 shinyFileChoose(input, 'files', root = c(root = '.'),
                 filetypes = c('',"txt"))
 
 file <- reactive(input$files)
 
 output$filechosen <- renderText({
  print(r1.lst)
  r1.lst <- c(r1.lst,as.character(parseFilePaths(c(root = "."),file())$datapath))
  print(r1.lst)
 })
 
}   
shinyApp(ui = ui, server = server)

The first time I clicked the select button, r1.lst contains the two paths I selected:

1] "raw_data/test.txt"
[2] "raw_data/test2.txt"

However, the second time, r1.lst becomes NULL again and the r1.lst contains only the new paths I selected:

1] "raw_data/diff_folder/test.txt"
[2] "raw_data/diff_folder/test2.txt"

How do I get all the files path selected in one list?

Thank you,
Cen