尝试将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);
});
});