Listen to fileInput() upload in progress

Hi,

Is there a way to detect when a fileInput() is busy uploading? I need to be able to disable a couple of buttons while uploading, however, on the server-side, it’s only possible to detect the fileInput has been used after the upload is finished.

Thanks!

I believe I solved my own issue. I wrote following wrapper around fileInput() for anyone that's interested. Observing input[["{inputId}-upload_started"]] now allows listening to upload in progress events.

shiny_file_input <- function(inputId, rm_file_name = FALSE, ...) { # nolint
  
  # 1. listen using {inputId}-upload_started
  file_input <- shiny::fileInput(inputId = inputId, ...) %>%
    {temp = .
    temp$children[[2]]$children[[1]]$children[[1]]$children[[2]]$
      attribs$onchange <- paste0(
        "Shiny.setInputValue('",
        paste0(inputId, "-upload_started"),
        "', null); Shiny.setInputValue('",
        paste0(inputId, "-upload_started"),
        "', 'trigger');"
      )
    temp}
  
  # 2. deal with page jumping issue
  # https://github.com/rstudio/shiny/issues/3327
  tag_q <- htmltools::tagQuery(file_input)
  tags <- tag_q$
    find(sprintf("input#%s", inputId))$
    removeAttrs("style")$
    addAttrs("style" = "display:none;")$
    allTags()
  
  # 3. rm file name after upload
  if (rm_file_name) {
    tags[[3]][[2]][[3]][[2]] <- NULL
    tags[[3]][[2]][[3]][[1]][[3]][[1]]$attribs$style <- paste0(
      "border-radius: 5px; ",
      "height: 40px; ",
      "margin-top: 3px; ",
      "padding-top: 8px; ",
      "padding-left: 13px;"
    )
    tags[[3]][[3]] <- NULL
  }

  return(tags)
}


shiny::observeEvent(input$`{inputId}-upload_started`,  {
  # do stuff
})