【发布时间】:2017-04-03 20:25:31
【问题描述】:
我正在尝试以 php localhost 方式运行 R 代码;所以我按照这个例子(https://www.r-bloggers.com/integrating-php-and-r/)。
<?php
// poorman.php
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()
我在 /var/www/html/R 文件夹中有两个文件;当我运行 php 文件时运行良好,但我提交的“N”数量与示例网络图像显示的不同。
我也尝试运行只是为了显示一个 rnorm() 分布,但我得到了相同的结果 -> 什么都没有。
我认为我的问题在于用 php 连接 R,所以我尝试安装 Rapache (http://rapache.net/manual.html) 但是当我到达 “sudo apt-get install apache2-prefork-dev apache2-mpm-prefork libapreq2-dev r-base-dev” 我收到以下消息 -> 找不到包 apache2-prefork-dev
有什么解决办法吗?
提前致谢
乔治
【问题讨论】: