I created a R shiny app that automatically runs every day using a batch file. Everything works fine when lauching the app, but the next day it crashes and I get the following message:
Warning in file(open = "w+") :
cannot open file
'C:\Users\bertin\AppData\Local\Temp\RtmpKiBPOU\Rf3f835d1a66' : No such file or directory
Warning: Error in file: cannot open the connection
[No stack trace available]
Actually this issue is related to the tempdir() folder created by the R session executing the shiny app. This folder is automatically deleted after a certain time. Do I have to delete all Temp files on each refreshing? Or on the contrary is it needed to prevent R from deleting all shiny temp files on Temp folder? Thanks!
Edit - Here is how to intentionally generate the error:
tempdir()
dir.exists(tempdir())
library(shiny)
# Windows shell required
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"))
}
)


tempdir()ortempfile()goes away after the R process associated with them goes away. If you are using those and expecting long-term storage you're going to be disappointed. If there are things you're storing in a "temp" dir that needs semi-permanance, you'll need to create a deliberate path to store the files and use that from now on and do the cleanup management on your own.shinyitself storing files intempdir(). Here is a related GitHub issue. I'm having the same problem.tempdir(), calledpaste0(tempdir(), "copy")2) Also make a check upon starting shiny app if tempdir exists and if not change the tempdir to the copy path stackoverflow.com/questions/17107206/change-temporary-directory. Then make another copy of the tempdir for the next time. (Copying the files failed for me.)