0

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 Answers2

0

First thing pie(slices, labels = lbls, main="Pie Chart of Countries") only depends on the objects slices and lbls. If you don't change these objects after reading in other data (notice that in R you can have more than one active data set - in contrast to some other software like SAS etc.), then your pie chart also won't change. So you need to have a comand like slices <- data1[, "NAME OF YOUR DESIRED VARIABLE"]. Second thing, your question doesn't show how x in hist looks like.

Qaswed
  • 3,649
  • 7
  • 27
  • 47
0

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

Thank you