用于执行在 OpenCPU 上发布的 R 函数的 Jiddle
Jiddle for executing R function published on OpenCPU
我将我的 R 包上传到 GitHub,然后按照 here 的说明在 OpenCPU 上发布它。
https://public.opencpu.org/ocpu/github/Klausos9/test/R/test/print
test
是一个包含平方根估计公式的函数。
现在,在 JFiddle 中,我尝试使用 HTTP API 对该函数进行简单的调用。但是,我无法使其正常工作。有什么想法吗?
http://jsfiddle.net/WVWCR/49/
但是当我点击 运行 按钮时,它显示:
R returned an error: unused argument (input = input)
In call:
test(input = input)
尝试将 ocpu.rpc
调用更改为:
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);
});
出现错误是因为您的函数调用传递了一个名为 input
的参数,而您的函数需要一个名为 x
.
的参数
编辑
完整更正的脚本(针对下面评论中提到的脚本):-
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);
});
});
我将我的 R 包上传到 GitHub,然后按照 here 的说明在 OpenCPU 上发布它。
https://public.opencpu.org/ocpu/github/Klausos9/test/R/test/print
test
是一个包含平方根估计公式的函数。
现在,在 JFiddle 中,我尝试使用 HTTP API 对该函数进行简单的调用。但是,我无法使其正常工作。有什么想法吗?
http://jsfiddle.net/WVWCR/49/
但是当我点击 运行 按钮时,它显示:
R returned an error: unused argument (input = input)
In call:
test(input = input)
尝试将 ocpu.rpc
调用更改为:
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);
});
出现错误是因为您的函数调用传递了一个名为 input
的参数,而您的函数需要一个名为 x
.
编辑
完整更正的脚本(针对下面评论中提到的脚本):-
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);
});
});