我想在我的网站上使用r分析数据。网站是使用PHP创建的。但我无法将PHP与R集成。有什么办法吗?我试过http://www.r-bloggers.com/integrating-php-and-r/示例,但它没有用。
echo "<form action='poorman.php' method='get'>";
echo "Number values to generate: <input type='text' name='N' />";
echo "<input type='submit' />";
echo "</form>";
if(isset($_GET['N']))
{
$N = $_GET['N'];
// execute R script from shell
// this will save a plot at temp.png to the filesystem
exec("Rscript my_rscript.R $N");
// return image tag
$nocache = rand();
echo("<img src='temp.png?$nocache' />");
}
?>
and the R script…
# my_rscript.R
args <- commandArgs(TRUE)
N <- args[1]
x <- rnorm(N,0,1)
png(filename="temp.png", width=500, height=500)
hist(x, col="lightblue")
dev.off()