I have a shiny app deployed locally via RScript.exe and runApp
on a Windows 10 machine which runs just fine. However, when the app is idling for a few days the browser displays the following:
This seems to be unrelated to the apps content (otherwise I would have provided an example app).
I was able to generate a log file which gave me:
Warning in file(open = "w+") :
cannot open file 'C:\Users\USER\AppData\Local\Temp\RtmpO0mnd9\Rfdd88a66def': No such file or directory
Warning: Error in file: cannot open the connection
[No stack trace available]
... and indeed the according folder generated on starting up the R session and the files generated on starting the shiny app were deleted (automatic cleaning done by Windows? - I'm not sure why).
I am able to reproduce this error when I'm manually deleting the R sessions tempdir()
hosting the shiny app.
Does anyone know how to prevent this issue?
In this GitHub issue Dean Attali suggested using tempdir(check = TRUE)
in shiny's source code what seems reasonable to me.
Here is some more related content:
RStudio community topic
SO question
Edit: here is how to reproduce the behaviour:
Edit:
Here is an example application showing the problem:
# Windows shell required
tempdir()
dir.exists(tempdir())
library(shiny)
shinyApp(
ui = fluidPage("Please reload to see me fail."),
server = function(input, output) {
shell(paste("rmdir", dQuote(
normalizePath(tempdir(), winslash = "/", mustWork = FALSE), q = FALSE
), "/s /q"))
}
)
By now I've found a setting in Windows 10 (Storage Sense) concerning the deletion of temporary files, which seems to be active by default.
Navigate as follows and uncheck:
- Settings
- System Storage
- Storage Sense
- Change how we free up space automatically
- Delete temporary files that my apps aren't using