In fact, this is one of the drawbacks of the Shiny module fileInput: it remains stationary if the same file was selected again and there is no built-in parameter force-upload.
To ensure reloading, the basic idea is:
- After each upload, save the downloaded data to the repository
reactiveValues. - Apply new
fileInputto replace the original - Show message with a successful download in a new one
fileInputfor better user convenience.
In ui.Rusing
uiOutput('fileImport')
In server.R:
v <- reactiveValues()
v$fileInputIndex <- 1
updateFileInput <- function (name = NULL){
output$fileImport <- renderUI({
index <- isolate(v$fileInputIndex)
result <- div()
result <- tagAppendChild(
result,
fileInput(paste0('file', index), 'Choose CSV File',accept=c('text/csv','text/comma-separated-values,text/plain','.csv'))
)
if(!is.null(name)){
result <- tagAppendChild(
result,
div(name," upload complete")
)
}
result
})
}
dataInputRaw <- reactive({
inFile <- input[[paste0('file', v$fileInputIndex)]]
if (is.null(inFile)){
return(v$data)
}
v$data <- data.frame(read.csv(inFile$datapath))
if (!is.null(v$data)){
v$fileInputIndex <- v$fileInputIndex + 1
updateFileInput(name = inFile$name)
}
v$data
})
updateFileInput()
I tested this snippet and it works.
source
share