简体   繁体   English

R闪亮应用程序中自动删除临时文件 - 文件错误:无法打开连接

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

I created a R shiny app that automatically runs every day using a batch file. 我创建了一个R闪亮的应用程序,每天使用批处理文件自动运行。 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. 实际上这个问题与执行闪亮应用程序的R会话创建的tempdir()文件夹有关。 This folder is automatically deleted after a certain time. 一段时间后会自动删除此文件夹。 Do I have to delete all Temp files on each refreshing? 我是否必须在每次刷新时删除所有Temp文件? Or on the contrary is it needed to prevent R from deleting all shiny temp files on Temp folder? 或者相反,是否需要阻止R删除Temp文件夹中所有闪亮的临时文件? 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"))
    }
)

结果

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. 但如果我正确理解你的问题,这与你的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. 因此,如果您不需要昨天的任何会话数据,您可以调用'.rs.restartR()'来重新启动R会话,从而设置一个新的临时目录。 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. 在此之后,你应该能够再次启动你的闪亮应用程序。

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. 到目前为止,我在Windows 10(存储感知)中找到了一个关于删除临时文件的设置,默认情况下这似乎是活动的。

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 删除我的应用未使用的临时文件

Windows Storage Sense

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM