title: I want to send variables to R and then R sends image to browser
body: <p>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.</p>
  
  <p>I'm able to display in the browser a plotted image by R with that script for example:</p>
  
  <pre><code>    &lt;% setContentType("image/png")
  t &lt;- 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
  %&gt;
  </code></pre>
  
  <p>And the other script that sends a variable and returns text strings:</p>
  
  <pre><code>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&amp;rutaMin="+rutaMin+"&amp;numF=1";         
                              document.getElementById("oculto1").src=url;
                           }else{
                                                   ...
  </code></pre>
  
  <p>With GET variables of RApache I can work with 'autini' in the R-script.</p>
  
  <p>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 "<strong>readbin</strong>" into the "<strong>responseText</strong>", and then build a image in php? Wich function of AJAX I should  use?</p>
  
  <p>THANKS FOR YOUR TIME!</p>