0

I uploaded my R package to GitHub and then published it on OpenCPU as explained here.

https://public.opencpu.org/ocpu/github/Klausos9/test/R/test/print

test is a function that contains squared root estimation formula.

Now, in JFiddle, I am trying to make a simple Call of this function using HTTP API. However, I cannot make it working. Any idea?

http://jsfiddle.net/WVWCR/49/

But when I click the Run button, it says:

R returned an error: unused argument (input = input)

In call:
test(input = input)
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217

1 Answers1

1

Try changing the ocpu.rpc call to:

var req = ocpu.rpc("test",{
    x : mydata                        // <--- input : mydata
  }, function(output){
    $("tbody").empty();
    $.each(output, function(index, value){
      var html = "<tr><td>" + value.x + "</td><td>" + value.tv + "</td></tr>";
    $("tbody").append(html);
});

The error is coming because your function call passes an argument named input while your function is expecting an argument named x.

EDIT

The full corrected script (for the one mentioned in comments below) :-

  ocpu.seturl("//public.opencpu.org/ocpu/github/Klausos9/test/R")

  //some example data
  //to run with different data, edit and press Run at the top of the 
  //page
  var mydata = 2;

  //call R function: tvscore::tv(input=data)
  $("#submitbutton").click(function(){      // <--- needed
      var req = ocpu.rpc("test",{
          x : mydata                        // <--- changed; input : mydata
        }, function(output){
         $("#output").text(output);         // <--- changed; output.message
      });

    //optional
    req.fail(function(){
      alert("R returned an error: " + req.responseText); 
    });
  });
B.Shankar
  • 1,271
  • 7
  • 11
  • Thanks. Here is a new simplified code: http://jsfiddle.net/WVWCR/54/ However, my function "test" that should return a squared value of x, does not return anything. – Klausos Klausos Jun 27 '15 at 07:35
  • @KlausosKlausos, I have added the corrected script as an edit to my answer. Actually, the `click` method is required, only the `ocpu.rpc` call needed change. – B.Shankar Jun 27 '15 at 09:15