How can I integrate R with PHP? I would like build a web application using R. I am using Windows Vista and have an Apache server. I have tried Rpad, but I was not able to correctly configure it. How do I set up Rpad as I am not that well off with PHP and Apache server? Or are there other ways to use R on Apache server?
 A: If you ever think to switch to Linux, the best way would be to use RApache, which is an Apache module that embeds an R interpreter (mod_R) in the webserver
A: If you are looking for a way of executing chunks of R code from PHP, here is a library that might help:
https://github.com/kachkaev/php-r
use Kachkaev\PHPR\RCore;
use Kachkaev\PHPR\Engine\CommandLineREngine;

$r = new RCore(new CommandLineREngine('/usr/bin/R'));
$result = $r->run('1 + 1');
echo $result;

This will output:
> 1 + 1
[1] 2

A: Here is the easiest way to do it that I found:
This implementation of PHP and R consists of only two files. One written in PHP, and the other an R script. The PHP returns a form which uses the GET method to send a variable N to the server. When the form is submitted, the PHP will then execute an R script from the shell using a combination of the PHP command exec() and the Rscript shell command. This command will pass the variable N to the R script. The R script will then execute and save a histogram plot of N normally distributed values to the filesystem. Finally, when the R script is complete, the PHP will return the HTML tag containing the saved images path. First, the PHP file
< ?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()

Here are some more you are welcome to try:


*

*http://danpolant.com/r-integration-with-php/

*http://steve-chen.net/document/r/r_php
