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?