无法在 php R 脚本中 运行“setwd”和“read.csv”

Cannot run " setwd " and " read.csv " in php R script

我尝试使用 php & R 制作 WebApp。这是我的 php 代码:

exec("/usr/bin/Rscript /home/bella/Downloads/htdocs/laut/script.r $N");

$nocache = rand();
echo("<img src='tmp.png?$nocache' />");

这是我的 script.r 代码:

slices <- c(10, 12,4, 16, 8)
lbls <- c("US", "UK", "Australia", "Germany", "France")

png(filename="tmp.png", width=600, height=600)
pie(slices, labels = lbls, main="Pie Chart of Countries")
dev.off()

一切正常。

然后,我更改切片数据并将其存储在 csv 中。我更改 script.r 代码:

setwd("/home/bella/Downloads/DATA")
slices<-read.csv("country.csv",header=T,sep=";",dec=",")
lbls <- c("US", "UK", "Australia", "Germany", "France")

png(filename="tmp.png", width=600, height=600)
pie(as.matrix(slices), labels = lbls, main="Pie Chart of Countries")
dev.off()

我运行它,但是tmp.png文件没有更新。

我的 R 代码“setwd”和“read.csv”似乎没有 运行。

(我在 R 和 运行ning 中都尝试了脚本)

为什么会这样?如何在 php?

中使用 R 脚本从 csv 文件中获取数据

首先 pie(slices, labels = lbls, main="Pie Chart of Countries") 仅取决于对象 sliceslbls。如果您在读取其他数据后不更改这些对象(请注意,在 R 中您可以拥有多个活动数据集 - 与 SAS 等其他软件相比),那么您的饼图也将获胜'改变。所以你需要有一个像slices <- data1[, "NAME OF YOUR DESIRED VARIABLE"]这样的命令。第二,你的问题没有显示 x in hist 的样子。

更改相关文件和文件夹的权限和访问权限,一切正常

谢谢