Tait Hoyem 2 years ago
commit 07a9db401a

BIN
.RData

Binary file not shown.

@ -0,0 +1 @@
Subproject commit 54b38ba45d22d63dbde822ec8045a5e479d599ad

Binary file not shown.

@ -0,0 +1,20 @@
window.onload = () => {
ocpu.seturl("http://localhost:5656/ocpu/library/base/R");
ar = [1, 2, 3, 4, 9, 2, 4, 5];
let req = ocpu.call("plot", {
x: ar,
type: "o",
col: "blue"
}, (o) => {
console.log(o);
console.log(o.getFileURL("output.html"));
console.log(o.getLoc());
//$("#rplot").attr("src", o.getFileURL("output.html"));
});
// if fail
req.fail(() => {
alert("R Error!");
});
}

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.js"></script>
<script src="js/opencpu.js"></script>
<script src="js/app.js"></script>
<style>
#plot {
height: 400px;
border: 1px solid black;
}
</style>
</head>
<body>
<header>
<h1>Hello World!</h1>
</header>
<main>
<div id="example" editable="true">
abc123
</div>
<img id="rplot"></img>
</main>
</body>
</html>

@ -0,0 +1,19 @@
window.onload = () => {
ocpu.seturl("http://localhost:5656/ocpu/library/cop/R");
ar = [1, 2, 3, 4, 9, 2, 4, 5];
let req = ocpu.call("test", {}, function(session){
$("img").attr("src", session.getFileURL("test.svg"));
}).fail(() => {
console.error("Error: " + req.responseText);
});
req.always(() => {
console.log("Success!");
});
// if fail
req.fail(() => {
alert("R Error!");
});
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,28 @@
if(!window.jQuery){alert("Could not find jQuery! The HTML must include jquery.js before opencpu.js!")}
(function($){var r_cors=false;var r_path=document.createElement('a');r_path.href="../R";function Session(loc,key,txt){this.loc=loc;this.key=key;this.txt=txt;this.output=txt.split(/\r\n|\r|\n/g);this.getKey=function(){return key;};this.getLoc=function(){return loc;};this.getFileURL=function(path){return this.getLoc()+"files/"+path;};this.getFile=function(path,success){var url=this.getFileURL(path);return $.get(url,success);};this.getObject=function(name,data,success){name=name||".val";if(name instanceof Function){success=name;name=".val";}
var url=this.getLoc()+"R/"+name+"/json";return $.get(url,data,success);};this.getStdout=function(success){var url=this.getLoc()+"stdout/text";return $.get(url,success);};this.getConsole=function(success){var url=this.getLoc()+"console/text";return $.get(url,success);};}
function Snippet(code){this.code=code||"NULL";this.getCode=function(){return code;};}
function Upload(file){if(file instanceof File){this.file=file;}else if(file instanceof FileList){this.file=file[0];}else if(file.files instanceof FileList){this.file=file.files[0];}else if(file.length>0&&file[0].files instanceof FileList){this.file=file[0].files[0];}else{throw 'invalid new Upload(file). Argument file must be a HTML <input type="file"></input>';}
this.getFile=function(){return file;};}
function stringify(x){if(x instanceof Session){return x.getKey();}else if(x instanceof Snippet){return x.getCode();}else if(x instanceof Upload){return x.getFile();}else if(x instanceof File){return x;}else if(x instanceof FileList){return x[0];}else if(x&&x.files instanceof FileList){return x.files[0];}else if(x&&x.length&&x[0].files instanceof FileList){return x[0].files[0];}else{return JSON.stringify(x);}}
function r_fun_ajax(fun,settings,handler){if(!fun)throw "r_fun_call called without fun";settings=settings||{};handler=handler||function(){};settings.url=settings.url||(r_path.href+"/"+fun);settings.type=settings.type||"POST";settings.data=settings.data||{};settings.dataType=settings.dataType||"text";var jqxhr=$.ajax(settings).done(function(){var loc=jqxhr.getResponseHeader('Location')||console.log("Location response header missing.");var key=jqxhr.getResponseHeader('X-ocpu-session')||console.log("X-ocpu-session response header missing.");var txt=jqxhr.responseText;if(r_cors&&loc.match("^/[^/]")){loc=r_path.protocol+"//"+r_path.host+loc;}
handler(new Session(loc,key,txt));}).fail(function(){console.log("OpenCPU error HTTP "+jqxhr.status+"\n"+jqxhr.responseText);});return jqxhr;}
function r_fun_call_json(fun,args,handler){return r_fun_ajax(fun,{data:JSON.stringify(args||{}),contentType:'application/json'},handler);}
function r_fun_call_urlencoded(fun,args,handler){var data={};$.each(args,function(key,val){data[key]=stringify(val);});return r_fun_ajax(fun,{data:$.param(data)},handler);}
function r_fun_call_multipart(fun,args,handler){testhtml5();var formdata=new FormData();$.each(args,function(key,value){formdata.append(key,stringify(value));});return r_fun_ajax(fun,{data:formdata,cache:false,contentType:false,processData:false},handler);}
function r_fun_call(fun,args,handler){args=args||{};var hasfiles=false;var hascode=false;$.each(args,function(key,value){if(value instanceof File||value instanceof Upload||value instanceof FileList){hasfiles=true;}else if(value instanceof Snippet||value instanceof Session){hascode=true;}});if(hasfiles){return r_fun_call_multipart(fun,args,handler);}else if(hascode){return r_fun_call_urlencoded(fun,args,handler);}else{return r_fun_call_json(fun,args,handler);}}
function rpc(fun,args,handler){return r_fun_call(fun,args,function(session){session.getObject(function(data){if(handler)handler(data);}).fail(function(){console.log("Failed to get JSON response for "+session.getLoc());});});}
$.fn.rplot=function(fun,args,cb){var targetdiv=this;var myplot=initplot(targetdiv);myplot.setlocation();myplot.spinner.show();return r_fun_call(fun,args,function(tmp){myplot.setlocation(tmp.getLoc());if(cb)cb(tmp);}).always(function(){myplot.spinner.hide();});};function initplot(targetdiv){if(targetdiv.data("ocpuplot")){return targetdiv.data("ocpuplot");}
var ocpuplot=function(){var Location;var pngwidth;var pngheight;var plotdiv=$('<div />').attr({style:"width: 100%; height:100%; min-width: 100px; min-height: 100px; position:relative; background-repeat:no-repeat; background-size: 100% 100%;"}).appendTo(targetdiv).css("background-image","none");var spinner=$('<span />').attr({style:"position: absolute; top: 20px; left: 20px; z-index:1000; font-family: monospace;"}).text("loading...").appendTo(plotdiv);var pdf=$('<a />').attr({target:"_blank",style:"position: absolute; top: 10px; right: 10px; z-index:1000; text-decoration:underline; font-family: monospace;"}).text("pdf").appendTo(plotdiv);var svg=$('<a />').attr({target:"_blank",style:"position: absolute; top: 30px; right: 10px; z-index:1000; text-decoration:underline; font-family: monospace;"}).text("svg").appendTo(plotdiv);var png=$('<a />').attr({target:"_blank",style:"position: absolute; top: 50px; right: 10px; z-index:1000; text-decoration:underline; font-family: monospace;"}).text("png").appendTo(plotdiv);function updatepng(){if(!Location)return;pngwidth=plotdiv.width();pngheight=plotdiv.height();plotdiv.css("background-image","url("+Location+"graphics/last/png?width="+pngwidth+"&height="+pngheight+")");}
function setlocation(newloc){Location=newloc;if(!Location){pdf.hide();svg.hide();png.hide();plotdiv.css("background-image","");}else{pdf.attr("href",Location+"graphics/last/pdf?width=11.69&height=8.27&paper=a4r").show();svg.attr("href",Location+"graphics/last/svg?width=11&height=6").show();png.attr("href",Location+"graphics/last/png?width=800&height=600").show();updatepng();}}
var onresize=debounce(function(e){if(pngwidth==plotdiv.width()&&pngheight==plotdiv.height()){return;}
if(plotdiv.is(":visible")){updatepng();}},500);plotdiv.on("resize",onresize);$(window).on("resize",onresize);return{setlocation:setlocation,spinner:spinner};}();targetdiv.data("ocpuplot",ocpuplot);return ocpuplot;}
function debounce(func,wait,immediate){var result;var timeout=null;return function(){var context=this,args=arguments;var later=function(){timeout=null;if(!immediate)
result=func.apply(context,args);};var callNow=immediate&&!timeout;clearTimeout(timeout);timeout=setTimeout(later,wait);if(callNow)
result=func.apply(context,args);return result;};}
function testhtml5(){if(window.FormData===undefined){alert("Uploading of files requires HTML5. It looks like you are using an outdated browser that does not support this. Please install Firefox, Chrome or Internet Explorer 10+");throw "HTML5 required.";}}
window.ocpu=window.ocpu||{};var ocpu=window.ocpu;function seturl(newpath){if(!newpath.match("/R$")){alert("ERROR! Trying to set R url to: "+newpath+". Path to an OpenCPU R package must end with '/R'");}else{r_path=document.createElement('a');r_path.href=newpath;r_path.href=r_path.href;if(location.protocol!=r_path.protocol||location.host!=r_path.host){r_cors=true;if(!('withCredentials'in new XMLHttpRequest())){alert("This browser does not support CORS. Try using Firefox or Chrome.");}}
if(location.protocol=="https:"&&r_path.protocol!="https:"){alert("Page is hosted on HTTPS but using a (non-SSL) HTTP OpenCPU server. This is insecure and most browsers will not allow this.")}
if(r_cors){console.log("Setting path to CORS server "+r_path.href);}else{console.log("Setting path to local (non-CORS) server "+r_path.href);}
$.get(r_path.href,function(resdata){console.log("Path updated. Available objects/functions:\n"+resdata);}).fail(function(xhr,textStatus,errorThrown){alert("Connection to OpenCPU failed:\n"+textStatus+"\n"+xhr.responseText+"\n"+errorThrown);});}}
ocpu.call=r_fun_call;ocpu.rpc=rpc;ocpu.seturl=seturl;ocpu.Snippet=Snippet;ocpu.Upload=Upload;if(typeof console=="undefined"){this.console={log:function(){}};}}(jQuery));

@ -0,0 +1 @@
Subproject commit f383448f5b827d273d06812105155015907ee5a1

@ -0,0 +1,14 @@
## This app requires OpenCPU 1.0.1 or higher !!!!
##
#' @export
rmdtext <- function(text){
writeLines(text, con="input.Rmd");
knit2html("input.Rmd", output="output.html");
invisible();
}
test <- function(){
f <- c(1, 2, 3, 4, 9, 2, 5, 9, 3);
plot(f);
}

@ -0,0 +1,5 @@
install.packages("opencpu")
install.packages("reticulate")
install.packages("unix")
install.packages("purrr")
install.packages("showtext")

@ -0,0 +1 @@
Subproject commit afdbbe0d02c245bd33e33a2d75e8b7a5e624c8b5

@ -0,0 +1,8 @@
library(opencpu)
library(reticulate)
library(unix)
library(purrr)
library(showtext)
install.packages("./custom-opencpu-program", repos=NULL, type="source")
ocpu_start_server()

@ -0,0 +1,3 @@
#!/bin/bash
R --no-save < run.R
Loading…
Cancel
Save