由于关于 Rplots.pdf 的错误,R Shiny 应用程序无法在服务器上启动

R Shiny app fails to start on server due to error about Rplots.pdf

Shiny 应用 运行 在 RStudio 上运行良好,但在 public 服务器上 运行 运行不正常,而是抛出此错误:

Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf",  : 
      cannot open file 'Rplots.pdf'
    Calls: runApp ... ..stacktraceon.. -> <Anonymous> -> par -> <Anonymous>
    Execution halted

出现此错误是因为您的应用程序中有代码试图在非交互式 R 会话(通常为 server.r 或 global.r)中生成绘图。 引用谢一辉的话:

From my experience, this is often an indication that your have some code that generates plots in a non-interactive R session, and the default graphics device for a non-interactive R session is pdf(). R tried to capture the plot and writes Rplots.pdf, but failed probably due to the fact that you don't have write permission to the working directory. Your server.R contains a call to palette(), which I believe will trigger Rplots.pdf. You can try to move it inside renderPlot({}) and see if the problem goes away.

在我的例子中,这是在我的 global.r 文件中对 scales::show_col() 的剩余调用,来自测试一些调色板。