You can do it in such case with a observer on input$file
library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("Multiple Files testing"),
sidebarLayout(
sidebarPanel(
fileInput("file",
"Upload the file",
multiple = TRUE,
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
uiOutput("selectfile"),
plotOutput("myplot")),
mainPanel(
uiOutput("tb")
))))
server <- shinyServer(function(input,output,session) {
# here you create a reactive list that will change on input$file
# and where you will store the results from your long computation
myfilesinput <- reactiveVal(list())
observeEvent(input$file, ignoreNULL = TRUE, {
insertUI(selector = "body", where = "beforeEnd", immediate = TRUE, multiple = FALSE, session = session,
ui = div(
id = "busy_ctn",
style="width:100%; height:100%; top:0; left:0; position:fixed; display:block; opacity:0.9; background-color:#fff; z-index:99998; text-align:center;",
tags$div(id = "busy_msg",
style='position:absolute; top:50%; left:0; bottom:0; right:0; display:block; align-items:center; justify-content:center; text-align:center; margin:auto; vertical-align:middle;',
tags$h2("processing"),
tags$div(style = "display:inline-block; vertical-align:super; color:black;",
icon("fas fa-sync-alt fa-spin fa-3x fa-fw")))))
# then you create a progress bar
# It is not mandatory but I think it's a good ideat to show that something is being processed
# and the app is not just freezed/crashed
pb <- Progress$new()
# the tryCatch is here to be sure that in cas a error happens you will remove the busy message and close the progress bar
tryCatch({
# here I mimic a long computation and show you how to fill the progress bar
# you should adjust to run your maths and store the final result into mydataframe()
i = seq(from = 0, to = 1, length.out = 21)
sapply(seq(from = 0, to = 1, length.out = 21), FUN = function(i) {
pb$set(value = i, message = "computing", detail = sprintf("done %3.f%%", i * 100))
Sys.sleep(0.2)
})
# here the final result is a simple operation
foo = lapply(1:length(input$file$datapath), FUN = function(i_file) {
# it is here where you may increase your progress bar
raw = read.table(file=input$file$datapath[i_file]) # you read your file
long = log10(raw) # you do your long compuation
list(raw = raw, long = long)
})
names(foo) <- input$file$name
myfilesinput(foo)
}, finally = {
pb$close()
removeUI(selector = "#busy_ctn", multiple = TRUE, immediate = TRUE, session = session)
})
})
output$selectfile <- renderUI({
if(is.null(input$file)) {return()}
list(hr(),
helpText("Select the files for which you need to see data and summary stats"),
selectInput("Select", "Select", choices=input$file$name)
)
})
output$table <- renderTable({
if(is.null(input$file)){return()}
myfilesinput()[["input$Select"]]$raw
})
output$tb <- renderUI({
if(is.null(input$file)) {return()}
else
tabsetPanel(
tabPanel("Dataset", tableOutput("table"))
)
})
# finally your plot will render the result of your long computation
output$myplot <- renderPlot({
if(is.null(input$file)) return(NULL)
if(!any(myfilesinput() %in% input$Select)) return(NULL)
plot(myfilesinput()[[input$Select]]$long)
})
})
shinyApp(ui, server)