cannot open file 'myFile.knit.md': Read-only file system

Hi,

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]
            paste0(
                "MyFile",
                "_",
                as.Date(startDateTime),
                "_",
                as.Date(endDateTime),
                ".pdf"
            )
        },
        content = function(file) {
            while (!is.null(dev.list()))
                dev.off()
            startDateTime <- input$date[1]
            endDateTime <- input$date[2]
            wd = getwd()
            
            withProgress(rmarkdown::render(
                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 'MyFile.knit.md': 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.

See https://mastering-shiny.org/action-transfer.html#downloading-reports

  • 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.