在that exemple of an opencpu app中,上传的文件在printsummary
的调用中被readcsvnew
函数使用。
我正在寻找一种方法,可以独立地将相同的数据集应用于多个函数。
我认为在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);
});
因此,会话详细信息将传递给imbricated函数。
是否有可能转移到:
// 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);
});
});
答案 0 :(得分:2)
如果可以帮助某人,请在此处发布:
我使用了那个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更严格:)