Temp files automatically deleted in R shiny app - Error in file: cannot open the connection

邮差的信 提交于 2019-12-07 04:42:41

问题


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"))
    }
)


回答1:


With the deletion of your temp directory also session data gets lost. But if I understand your question correctly, this is not relevant for your Shiny Application. So if you don‘t need any session data from yesterday you could call ‘.rs.restartR()‘ to restart your R session and thus setting a new temporary directory. You will probably get an error that your last session could not be saved (as the directory doesn‘t exist anymore). After this you should be able to start your Shiny App again.




回答2:


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:

  1. Settings
  2. System Storage
  3. Storage Sense
  4. Change how we free up space automatically
  5. Delete temporary files that my apps aren't using



来源:https://stackoverflow.com/questions/53152076/temp-files-automatically-deleted-in-r-shiny-app-error-in-file-cannot-open-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!