2

I have just found out about this fantastic project, called OpenCPU. I am currently trying to learn how to use CORS to integrate R in web applications. To do so, I am replicating a simple example, but until now I have been unsuccessful.

I am trying to use the smoothplot function from the stock package and integrate it in an external web-page (https://github.com/opencpu/stocks). I have already looked at the examples at the OpenCPU web-page and the ones on jsfiddle, but without luck figuring out what I am doing wrong.

Can anyone point me in the direction of my mistake when calling the smootplot function? Or am I missing something completely?

My html and script is as follow

<!DOCTYPE html>
<html lang="en">
<head>
<title>OpenCPU demo app</title>

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!-- ocpu library -->
<script src="//code.jquery.com/jquery-1.10.2.min.js"> </script>
<script src="//public.opencpu.org/js/opencpu-0.4.js"> </script>

<style>
#plotdiv {
    height: 400px;
    border: solid gray 1px;
}
</style>
</head>

<body>

<h1>Call R to download data for a specified stock ticket and plotting it</h1>

<b>Ticker</b> <input type="text" value="GOOG" id="ticker">

<button id="submitbutton" type="button">Submit to server!</button> <br><br>

<div id="plotdiv"></div>    

<!-- input and recieve output specified using jquery, and RESTful software architectur-->
<script type='text/javascript'>
// location of R function on openCPU server
ocpu.seturl("//public.opencpu.org/ocpu/library/stocks/R")

//call R function: stocks::smoothplot(ticker=ticker)
$("#submitbutton").click(function(){
    var ticker = $("#ticker").val();    
    var req = $("#plotdiv").rplot("smoothplot", {
        ticker : ticker,
        from : "2013-01-01"
    });

    req.fail(function(){
        alert("R returned an error: " + req.responseText); 
    });
});
</script>

</body>
</html>

Best regards

Bjerring
  • 35
  • 4

1 Answers1

0

As @Jeroen pointed out, change your

<script src="//public.opencpu.org/js/opencpu-0.4.js"> </script>

to

<script src="//public.opencpu.org/js/archive/opencpu-0.4.js"> </script>

and it should work just fine (it did for me).

MrFlick
  • 195,160
  • 17
  • 277
  • 295