I've stumbled across an awesome open source project called openCPU.org and I'm tremendously excited about the project.  As a research scientist trying to create a website hosting my work, I would love nothing more than to be able to run R on the cloud to have my scripts run in real time and show up on my webpages.  So a big time thanks to Jeroen for making this project happen.

With that, onto my question.

How the heck do I interact with openCPU?

I can put an example function into "run some code" at:

http://public.opencpu.org/userapps/opencpu/opencpu.demo/runcode/

And retrieve a PNG image of my code, which is great!

But how do I do that in my own webpage, or via a URL?

I can get the object of my original code upload from this page, something like: "x3ce3bf3e33"

If it is a function similar to:

myfun &lt;-function(){

x = seq(1,6.28)
y = cos(x)
p = plot(x,y)
print(p)
# also tried return(p)
}


Shouldn't I be able to call it via:

http://public.opencpu.org/R/tmp/x3ce3bf3e33/png

What about with input variables? e.g.:

myfun &lt;-function(foo){

x = seq(1,foo)
y = cos(x)
p = plot(x,y)
print(p)
}


I feel that perhaps there is something I am missing.  How do I specify "GET" or "POST" with the url?

EDIT

Ok in response to @Jeroen below, I need to use to use POST and GET with the API.  Now my question is extend to the following issue of getting PHP to interact with it correctly.  

Say I have the code:

&lt;?php

$foo = 'bar';
$options = array(
    'method' =&gt; 'POST',
    'foo' =&gt; $foo,
    );
$url = "http://public.opencpu.org/R/tmp/x0188b9b9ce/save";
$result = drupal_http_request($url,$options); // drupal function
?&gt;


How do I then access what is passed back in $result? I am looking to get a graph.  It looks like this:

{
    "object" : null,
    "graphs" : [
        "x2acba9501a"
    ],
    "files" : {}
} 


The next step will be to GET the image, something along the lines of:

$newurl = "http://public.opencpu.org/R/tmp/".$result["graph"]."/png";
$image = drupal_http_request($newurl);
echo $image;


But I don't know how to access the individual elements of $result?

EDIT #2

Ok guys, I've gotten this to work, thanks to the answer below and to multiple other help sessions, and a lot of smashing my head against the monitor.

Here we go, done with cURL

&lt;?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://public.opencpu.org/R/tmp/x0188b9b9ce/save');
curl_setopt($ch, CURLOPT_POST, 1); // Method is "POST"
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns the curl_exec string, rather than just Logical value
$result = curl_exec($ch);
curl_close($ch);
$new = json_decode($result,true); // $result is in 'json' format, decode it
$get = $new['graphs'][0]; // the 'hashkey for the image, "x2acba9501a" above

$img = 'http://public.opencpu.org/R/tmp/'.$get.'/png'; // link to the png image

echo &lt;&lt;&lt;END  // use this to display an image from the url
&lt;a href="$img"&gt;
&lt;img src="$img"&gt;
&lt;/a&gt;
END

?&gt;



Question: How to correctly format multiline html using the .after function jQuery?
Answer: I'm assuming you want your code to look something like this:

$(document).ready(function() {
    $('#content-main-cell h1').addClass('index-title');
    $('.index-title').after('&lt;div class="mds-logo"&gt;'
        + '&lt;img src="http://marines.mil/unit/marforres'
        + '/4thMarDiv/23rdMar/1stBn/img/battalion-logo.jpg"/&gt;&lt;/div&gt;'
    );
});


Just wrap the strings onto new lines by terminating them at the end of line and concatenate the next line onto the previous one.

You need to use a ; at the end of statements, which aren't necessarily at the end of every line.