dqj5046 2016-06-06 06:57
浏览 125
已采纳

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

I try to make WebApp using php & R . this is my php code:

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

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

And this is my script.r code:

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()

Everything work fine.

Then, i change slices data and store it in csv. I change script.r code:

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()

I run it, but tmp.png file not updated.

It seem that my R code "setwd" and "read.csv" didn't run.

(i try both script in R and running well)

Why this happen? How to get data from csv file using R script in php?

  • 写回答

2条回答 默认 最新

  • dongyang1518 2016-06-09 02:03
    关注

    change permission & access to related file and folder, and everything work fine

    Thank you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?