2

In that exemple of an opencpu app, a file uploaded is used by the function printsummary once imbricated into the call to readcsvnew.

I am looking for a way to apply to the same dataset a number of functions one after each other independently.

I think it is possible in the R code to save the data into the server and return the name of the data, then in each R function, begin by loading the data and finishing by saving it but it is a bit absurd, because loading and saving the data each time slow the process. And the server need to be cleaned at some point. So my question, is it possible to save the session detail and call it later on? Or is there a better way to do it, maybe with a js twick?

Looking at the js, the current call is:

// 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);
});

So the session details are passed on to the imbricated function.

Is it possible to move to something like:

// 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);
  });
});
YCR
  • 3,794
  • 3
  • 25
  • 29
  • Maybe helpfull, still working on it: [is-there-a-mechanism-to-persist-record-data-from-requests-to-an-opencpu-server?rq=1](http://stackoverflow.com/questions/21398584/is-there-a-mechanism-to-persist-record-data-from-requests-to-an-opencpu-server?rq=1) – YCR Dec 13 '16 at 15:30
  • And also: [accessing-objects-in-opencpu-sessions](http://stackoverflow.com/questions/24722550/accessing-objects-in-opencpu-sessions?rq=1) – YCR Dec 13 '16 at 16:26

1 Answers1

2

Post it here if it can help somebody:

I used that jsfiddle: jsfiddle.net/opencpu/tmqab/.

The best way to do it is to store the session into a global variable:

// 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 is definetely harder than R :)

YCR
  • 3,794
  • 3
  • 25
  • 29