在that exemple of an opencpu app中,上传的文件一旦被覆盖到readcsvnew
调用中,就由函数printsummary
使用。
我正在寻找一种方法,可以将多个函数一个接一个地独立地应用于同一数据集。
我认为在R代码中可以将数据保存到服务器中并返回数据的名称,然后在每个R函数中,从加载数据开始,以保存数据结束,但这有点荒谬,因为每次加载和保存数据都会减慢进程。服务器需要在某些时候进行清理。那么我的问题是,是否可以保存会话详细信息并在以后调用它?或者有没有更好的方法,比如js twick?
查看js,当前调用是:
// on click, call uploadcsv
$("#submitbutton").on("click", function(){
function uploadcsv(file, header){
//perform the request
var req = ocpu.call("readcsvnew", {
file : file,
header : header
}, function(session){
//on success call printsummary()
printsummary(session);
});
因此,会话详细信息将传递给覆盖的函数。
有没有可能移到下面这样的地方:
// on click on first button, call uploadcsv
$("#submitbutton").on("click", function(){
function uploadcsv(file, header){
//perform the request
var req = ocpu.call("readcsvnew", {
file : file,
header : header
}, function(session){
//on success, store the data or store the session details
__storing code here__
__ maybe save session details on the fly__
});
// on click on second button, call printsummary on uploaded data
$("#submitbutton2").on("click", function(){
//perform the request
var req = ocpu.call("printsummary", {
__parameters to call, here__
__ session saved__
}, function(session){
// exploit the result of printsummary
session.getConsole(function(output){
$("#output code").text(output);
});
});
发布于 2016-12-13 19:22:41
如果它对某人有帮助,请在这里发布:
我使用了jsfiddle: jsfiddle.net/opencpu/tmqab/。
最好的方法是将会话存储到全局变量中:
// on click on first button, call uploadcsv
$("#submitbutton").on("click", function(){
function uploadcsv(file, header){
//perform the request
var req = ocpu.call("readcsvnew", {
file : file,
header : header
}, function(session){
// store session as global variable:
mysession = session;
});
// on click on second button, call printsummary on uploaded data
$("#submitbutton2").on("click", function(){
//perform the request
var req = ocpu.call("printsummary", {
mydata : mysession
}, function(session){
// exploit the result of printsummary
session.getConsole(function(output){
$("#output code").text(output);
});
});
js肯定比R :)难。)
https://stackoverflow.com/questions/41119676
复制