I am building an internet site using apache, PHP and R (a statistic programing language) to construct the Logic Server. The program is on a single sarver because the apache. The customer user use the site to be able to make use of the Application that people build with R. You could do by utilizing R_modul which was produced for this function (so R can talk to apache).

This is a link from the R_modul http://rapache.net/

The issue:

We are able to use PHP to transmit an text in type of an R code and obtain in exchange the R Application answer in text form. That's exactly what the R_modul does.

But I'm not sure how to regenerate plots (Graphs photos). Some functions in R provide plos being an output. That's what I wish to show the consumer. But I'm not sure how to achieve that...

I suppose I have to find were may be the cache memory directory that contain the plot and give it back like a pic . But I am unsure...and when so, the plos are produced per command and therefore are endless in look.

@Yoni, do not mix-publish! We already clarified similar question on RApache subscriber list. It's also wise to viewed a precise description of the problem.

So far as I understood, you have to retrieve a picture produced with R around the server side to be able to display it around the client side (i.e. inside a browser). If that's the case, here goes:

  • you do not actually need PHP - you are able to create a effective RApache-powered web application with HTML/CSS/JavaScript and AJAX calls to R scripts (like Jeroen Ooms did in the ggplot webapp).
  • you do not return plot "by itselfInch, but a road to plot image file, like @daroczig already clarified
  • you don't have to save images inside a temporary directory/file - you are able to leave them around the server for future usage (in the event that complies together with your application design). Btw, I am unsure if tempfile strategy will act as intended, since RApache begins new session upon each HTTP request.
  • your can check my recent project on GitHub, becasue it is carefully associated with your question. Observe that it's within an initial phase of development.
  • learn AJAX!

P.S.

If you choose to use brew, don't set Apache <Directory> directive towards the folder in which the images are saved, since RApache will attempt to process all files inside a directory with brew function. Use <FilesMatch> Apache directive with regular expressions, becasue it is flexible. Title your files methodically (put a prefix or smth) and employ AJAX. You do not actually need brew, because the job can be achieved with sys.source. Attempt to avoid HTML + R/brew mash-up code. Return JSON and unserialise it with JavaScript.

This can be done without needing PHP or writing personal files around the server by creating an R tempfile() resist contain the plot, then using sendBin() to show the plot within the browser. Here's some sample R code:

setContentType("image/png")
t <- tempfile()
png(t,type="cairo")
plot(rnorm(100), col = "blue")
dev.off()
sendBin(readBin(t,'raw',n=file.info(t)$size))
unlink(t)
DONE

It can save you that as e.g. "plot.R" in /var/www/R. Your Apache config (e.g. /etc/apache2/conf.d/rapache.conf) need to look something similar to this:

LoadModule R_module  /usr/lib/apache2/modules/mod_R.so

<Location "/R">
  ROutputErrors
  SetHandler r-script
  RHandler sys.source
</Location>