cannot open file '': Read-only file system


I have a Shiny App that opens a modal in order to knit and download reports that are included in an r package.

The call in the app for these is below:

    output$MyFile <- downloadHandler(
        filename = function() {
            startDateTime <- input$date[1]
            endDateTime <- input$date[2]
        content = function(file) {
            while (!is.null(dev.list()))
            startDateTime <- input$date[1]
            endDateTime <- input$date[2]
            wd = getwd()
                system.file("rmd", "MyFile.Rmd",
                            package = "MyPackage"),
                output_file = file,
                clean = TRUE
            message = "Generating PDF Report...")

When I run this on Shiny Server it runs perfectly well and downloads the report as expected. However, when I run on Connect I get the error....

'cannot open file '': Read-only file system'

I suspect this may have to do with path re-writing in Connect? It is also possible that I should rethink how this works in the package. The wd variable set above gets the directory the report is being run in and then passes that to other functions, etc. to tell them where they should run. This works on the desktop and in Shiny Server, but haven't explored further in Connect. Any advice on what I can try next to get this working on Connect?

The below issue appears to be related, concerning RStudio Cloud.


  • In many deployment scenarios, you won't be able to write to the working
    directory, which RMarkdown will attempt to do. You can work around this by
    copying the report to a temporary directory when your app starts (i.e.
    outside of server()):

    report_path <- tempfile(fileext = ".Rmd")
    file.copy("report.Rmd", report_path, overwrite = TRUE)
1 Like

Thank you! That makes good sense. I'll work with that.