2
votes

Is there a way to reload input file, which was loaded with fileInput? I would like to allow the user to update his input by simple modification and reloading of csv file. It seems like reloading the file does not update it. One workaround, which helps is to save the modified data with different file name.

I've tried already exchanging fileInput function with an actionButton and file.choose(), but it won't work with R server

Here's my test code:

server.R

shinyServer(function(input, output, session) {

getTestOutput <- reactive({
 if(is.null(input$test))
   return(NULL)

isolate({
 writeLines(paste(input$test, collapse = "\n"))
 })
})

getTable <- reactive({
 if( is.null(input$test))
  return(NULL)

 r <- read.csv((input$test)$datapath,sep=";",header = TRUE)
 as.data.frame(r)
})

output$testOutput <- renderPrint({
  getTestOutput()

})

output$testTable <- renderTable({
  if(is.null(getTable())) 
   return(NULL)

  print(getTable())
})
})

ui.R

shinyUI(
 fluidPage(

sidebarPanel(
  fileInput("test","Load a file")
),

mainPanel(
  verbatimTextOutput("testOutput"),
  tableOutput('testTable')
  )
)
)
1

1 Answers

1
votes

If the Shiny app is on a separate server, then I believe this is fundamentally impossible using a normal web browser; simply saving the data file is not enough, you need to actually perform a new upload after each change.

However, if the Shiny app is being run on the user's machine (i.e. they are running an R session themselves and calling a function that launches Shiny) then you can just ask them for a path and use reactiveFileReader to automatically update the results whenever the file changes.