I'm working on a web application that uses R enviroment with RApache. I have used the AJAX.updater function to send a couple of variables to an R-script an then this returns to the browser a ResponseText to display. There is no problem with that but now I wish to send a variable to an R-script that plots a graph, and then I want to return the image to the browser.
I'm able to display in the browser a plotted image by R with that script for example:
<% setContentType("image/png")
t <- tempfile()
load(file="/var/www/oraculo/brew/ICER")
png(t, width=3.25, height=3.25, units="in", res=1200, pointsize=4)
plot(G,vertex.size=1,vertex.label=NA)
dev.off()
sendBin(**readBin**(t,'raw',n=file.info(t)$size))
unlink(t)
DONE
%>
And the other script that sends a variable and returns text strings:
new Ajax.Updater( 'numFermin', '../brew/shortestPath.rhtml',
{
'method': 'GET',
'parameters': {'autini': autini, 'autfin':centro, 'XarXaj': red},
'onSuccess': function(transport) {
txtRespuesta = transport.responseText;
if (txtRespuesta.lastIndexOf("Error")==-1){
var rutaMin = transport.**responseText**;
var accion = "";
var url = "index.src.php?accion=obtener&rutaMin="+rutaMin+"&numF=1";
document.getElementById("oculto1").src=url;
}else{
...
With GET variables of RApache I can work with 'autini' in the R-script.
One posible solution is to save the image in a file, but I don't like it very much. There is some way to put the bit stream readed in "readbin" into the "responseText", and then build a image in php? Wich function of AJAX I should use?
THANKS FOR YOUR TIME!