The app below contains a file input and a button that prints the value of the file input when clicked.
library(shiny)
shinyApp(
ui = fluidPage(
tags$head(
tags$script(HTML("
$('#get').click(function() {
console.log($('#file')[0].files)
})
});"))
),
HTML('
<input id="file" name="file" type="file">
<button id ="get">Show selected file</button>')
),
server = function(input, output, session) {}
)
When I select a file, the helper text briefly changes to the name of the selected file before reverting to "No file chosen". Clicking the "Show selected file" button returns an empty FileList.
Contrast this behaviour with that of the file input in this JSFiddle. In the JSFiddle, when a file is selected, the helper text changes to display the name of the chosen file. Clicking the button returns a FileList that contains the selected file.
What's causing these differences in the behaviour of the file input?
How can I make the file input value persistent in the client of the Shiny app?
I've taken a look a at the fileInputBinding (line 5821 of www\shared\shiny.js
) but can't find anything that would cause the value of the file input to revert to null
after the user has selected a file. There is an abortCurrentUpload
function but I'm not sure what that's doing.