Download Fails on shinyapps.io but not on local machine

The download within my shiny app works locally but not on shinyapps.io. This is related to Download of gtsave() fails on shinyapps.io but not on local machine but I don't get the same error messages. Any help would be truely appreciated!

To reproduce the error, go to https://solo-fsw.shinyapps.io/lavaangui/, Press on File->"Load Model and Data", select the .zip file I attached, and then click on File->"Download Model and Data". On Chrome, this will give error "Site wasn't available" after pressing "Resume" the download works. Every succesive download works fine.

This is the log

2024-05-08T15:17:09.259551+00:00 shinyapps[10373658]: Running on host: 6913e5db275a
2024-05-08T15:17:09.263368+00:00 shinyapps[10373658]: Running as user: uid=10001(shiny) gid=10001(shiny) groups=10001(shiny)
2024-05-08T15:17:09.266632+00:00 shinyapps[10373658]: Connect version: 2023.10.0
2024-05-08T15:17:09.270284+00:00 shinyapps[10373658]: LANG: C.UTF-8
2024-05-08T15:17:09.273379+00:00 shinyapps[10373658]: Working directory: /srv/connect/apps/lavaangui
2024-05-08T15:17:09.276771+00:00 shinyapps[10373658]: Using R 4.3.3
2024-05-08T15:17:09.280116+00:00 shinyapps[10373658]: R.home(): /opt/R/4.3.3/lib/R
2024-05-08T15:17:09.283229+00:00 shinyapps[10373658]: Content will use current R environment
2024-05-08T15:17:09.286381+00:00 shinyapps[10373658]: R_LIBS: (unset)
2024-05-08T15:17:09.289907+00:00 shinyapps[10373658]: .libPaths(): /usr/lib/R, /opt/R/4.3.3/lib/R/library
2024-05-08T15:17:09.293328+00:00 shinyapps[10373658]: shiny version: 1.8.1.1
2024-05-08T15:17:09.296564+00:00 shinyapps[10373658]: httpuv version: 1.6.15
2024-05-08T15:17:09.299792+00:00 shinyapps[10373658]: rmarkdown version: 2.26
2024-05-08T15:17:09.303313+00:00 shinyapps[10373658]: knitr version: 1.45
2024-05-08T15:17:09.306549+00:00 shinyapps[10373658]: jsonlite version: 1.8.8
2024-05-08T15:17:09.309622+00:00 shinyapps[10373658]: RJSONIO version: (none)
2024-05-08T15:17:09.312922+00:00 shinyapps[10373658]: htmltools version: 0.5.8.1
2024-05-08T15:17:09.316039+00:00 shinyapps[10373658]: reticulate version: (none)
2024-05-08T15:17:09.319335+00:00 shinyapps[10373658]: Using pandoc: /opt/connect/ext/pandoc/2.16
2024-05-08T15:17:09.322708+00:00 shinyapps[10373658]: 
2024-05-08T15:17:09.326131+00:00 shinyapps[10373658]: Starting R with process ID: '522'
2024-05-08T15:17:09.329308+00:00 shinyapps[10373658]: Shiny application starting ...
2024-05-08T15:17:09.332607+00:00 shinyapps[10373658]: Warning in warn_if_app_dir_is_package(appDir) :
2024-05-08T15:17:09.335788+00:00 shinyapps[10373658]:   Loading R/ subdirectory for Shiny application, but this directory appears to contain an R package. Sourcing files in R/ may cause unexpected behavior. See `?loadSupport` for more details.
2024-05-08T15:17:09.898920+00:00 shinyapps[10373658]: ℹ Loading lavaangui
2024-05-08T15:17:11.902635+00:00 shinyapps[10373658]: 
2024-05-08T15:17:11.906062+00:00 shinyapps[10373658]: Listening on http://127.0.0.1:41135
2024-05-08T15:17:33.898936+00:00 shinyapps[10373658]: Rows: 301 Columns: 9
2024-05-08T15:17:33.902565+00:00 shinyapps[10373658]: ── Column specification ────────────────────────────────────────────────────────
2024-05-08T15:17:33.905669+00:00 shinyapps[10373658]: Delimiter: ","
2024-05-08T15:17:33.908967+00:00 shinyapps[10373658]: dbl (9): x1, x2, x3, x4, x5, x6, x7, x8, x9
2024-05-08T15:17:33.912410+00:00 shinyapps[10373658]: 
2024-05-08T15:17:33.915483+00:00 shinyapps[10373658]: ℹ Use `spec()` to retrieve the full column specification for this data.
2024-05-08T15:17:33.919102+00:00 shinyapps[10373658]: ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
2024-05-08T15:17:39.898921+00:00 shinyapps[10373658]: Warning: Error in writeLines: can only write character objects
2024-05-08T15:17:39.902486+00:00 shinyapps[10373658]:   15: <Anonymous>
2024-05-08T15:17:39.905671+00:00 shinyapps[10373658]:   13: fn
2024-05-08T15:17:39.908733+00:00 shinyapps[10373658]:    8: retry
2024-05-08T15:17:39.912268+00:00 shinyapps[10373658]:    7: connect$retryingStartServer
2024-05-08T15:17:39.915554+00:00 shinyapps[10373658]:    6: eval
2024-05-08T15:17:39.918717+00:00 shinyapps[10373658]:    5: eval
2024-05-08T15:17:39.922359+00:00 shinyapps[10373658]:    4: eval
2024-05-08T15:17:39.926037+00:00 shinyapps[10373658]:    3: eval
2024-05-08T15:17:39.929413+00:00 shinyapps[10373658]:    2: eval.parent
2024-05-08T15:17:39.932841+00:00 shinyapps[10373658]:    1: local

The Error in writelines should be relevant but since the download works fine after pressing Resume I am not sure that it is relevant.

This is the R code for the download:

serverDownloader <- function(id, getData) {
  moduleServer(id, function(input, output, session) {
    output$downloadData <- downloadHandler(
      filename = function() {
        paste("lavaangui-", Sys.Date(), ".zip", sep = "")
      },

      # Define the content of the file
      content = function(file) {
        # Create a temporary directory
        tempDir <- tempdir()

        # Define the names of the JSON and CSV files
        jsonFile <- file.path(tempDir, "model.json")
        csvFile <- file.path(tempDir, "data.csv")


        writeLines(input$model, jsonFile)

        # Write the data frame to the CSV file (replace my_data with your data frame)
        utils::write.csv(getData(), csvFile, row.names = FALSE)

        # Create a zip archive of the directory containing the JSON and CSV files
        zip::zip(zipfile = file, files = c("model.json", "data.csv"), root = tempDir)
      }
    )

    outputOptions(output, "downloadData", suspendWhenHidden = FALSE)
  })
}

Can be closed. I change my download; such that the download is handled directly by javascript.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.