The new openCPU http://www.opencpu.org平台允许集成R http://www.r-project.orgHTML/javascript 中的函数。然而,我一直在努力实施。有人可以提供一个示例,说明如何将自己设计的 R 函数上传到 openCPU 并通过 javascript 调用它及其参数吗?
由于修改了 openCPU 服务器路径并且缺乏 JSON 支持,上述解决方案不再有效。修改后的工作解决方案
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Call R Through OpenCPU</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
//When Document is Ready
$(function () {
//Go R button Click Event Handler
$("#cmdGoR").click(function () {
var resultsUrlPrefix = "http://public.opencpu.org",
url = resultsUrlPrefix + "/ocpu/library/base/R/identity/save";
var rCommands = $("#txtRCommands").val();
$.post(url,
{
x: rCommands
},
function (data) {
var statResultsLink = resultsUrlPrefix + data.toString().match(/.+\/stdout/m),
chartLink = resultsUrlPrefix + data.toString().match(/.+\/graphics\/[1]/m);
//Add statistical (textual) results to results div
$('#results').append("<br/>");
$('<div/>', {
id: 'statResults'
}).appendTo('#results');
$("#statResults").load(statResultsLink);
//Add charts results to results div
$('#results').append("<br/>");
$('<img/>', {
id: 'chartResults',
src: chartLink
}).appendTo('#results');
})
.error(function (jqXHR, status, error) {
alert(jqXHR.responseText);
});
});
});
</script>
</head>
<body>
<h3>Set of R Commands</h3>
<textarea rows="8" cols="80" id="txtRCommands">
x <- rnorm(1000);
print(hist(x));
</textarea>
<br />
<input type="button" value="Run code" id="cmdGoR" />
<div id="results">
</div>
</body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)