Shinylive download works with Firefox, fails on Chrome

,

I have a Shiny app that creates a zip archive and invokes downloadHandler() to download the resulting file. The app is compiled using the shinylive library, but a browser-specific bug has emerged.

  • If I run the Shiny app in RStudio, downloads work in both Firefox and Chrome.
  • If I run the shinylive version locally (using httpuv::runStaticServer), downloads work in Firefox but fail in Chrome. The error message is "download.txt File wasn't available on site".
  • If I run the shinylive version from a web server, downloads work in Firefox but fail in Chrome. The error message this time is "download.html File wasn't available on site." (Note the change in file extension.)

When it works, the filename is not "download" and the extension is ".zip".

The code for the download handler (which uses the zip() function from the zip package) is as follows.

  # Download the new file archive.
  output$download <- 
    downloadHandler(
      filename = function() paste0(docs$name, ".zip"),
      content = function(f) {
        zip(f, docs$manifest, mode = "cherry-pick")
      }
    )

Created on 2025-03-19 with reprex v2.1.1

I would appreciate any suggestions about possible fixes.

We have an example at Shiny examples that mentions needing to modify the shiny::downloadButton() function to work around a bug in Chrome. You might be hitting that issue.

Can you try using the code from the example?

# Workaround for Chromium Issue 468227
downloadButton <- function(...) {
  tag <- shiny::downloadButton(...)
  tag$attribs$download <- NULL
  tag
}

That did indeed fix the problem. Thanks!