0

I have a csv file like this:

DateTime        Server1 Server2 Server3
8/24/2014 15:20 6.09    5.7     5.21
8/24/2014 15:55 4.54    4.38    5.33
8/24/2014 16:04 5.03    4.52    4.92
8/24/2014 16:18 4.93    4.61    5.56
8/24/2014 16:27 6.27    4.18    5.62
8/24/2014 16:42 4.59    4.61    6.73
8/24/2014 16:56 5.91    4.37    4.76
8/24/2014 17:10 4.53    4.3     4.59

I used ocpu platfrom to upload it. The R function to read the csv file is this:

readcsvnew <- function(file, ...){
  if(!grepl(".csv$", file)){
    stop("Uploaded file must be a .csv file!")
  }
  read.csv(file, header=TRUE, ...);
}

Once I read this file using ocpu, the data is in the session. Now I need to make a call to update my html list. To do this, I need to make a call to the session object and retrieve the header in json format:

<legend>Plot Parameters</legend>
            <label>Y-Axis</label> 
            <select id="yaxis" multiple="multiple">

            </select> 
            <label>X-Axis</label> 
            <select name="xaxis" id="pollutant">

            </select>

Once I get the header in Json, I can populate it with javascript. Now that select list are updated, based on user picked values of x-axis (this will be DateTime) and Y-axis values (this could be Server1 or Server1 thru Server3), I need to make another call to session and retrieve the values in custom Json format as follows:

{"name":"Server1","data":[[1408893651000,6.09],[1408895711000,4.54]},{"name":"Server2","data":[[1408893651000,5.7],[1408895711000,4.38]},{"name":"Server3","data":[[1408893651000,5.21],[1408895711000,5.33]}
user1471980
  • 10,127
  • 48
  • 136
  • 235

1 Answers1

1

If you retrieve the output of an object, HTTP GET parameters are mapped to jsonlite::toJSON(). For example:

See this email for a worked example of using the 2 step process to retrieve output from an RPC request using custom JSON.

Alternatively you can make your function return a list instead of a data frame using as.list.

Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
  • I get those links your provided. Do you have a working example of returning function as.list? – user1471980 Sep 10 '14 at 14:57
  • I need little bit help here to get going. I've created another R function that will sit on the server and accept df and column names as argument and return the values as custom json, that's done. Now, I'll need to figure out how to pass the data frame sitting in session to that function. How could I pass the data in existing session in data frame format to an R function on the server? Any ideas? – user1471980 Sep 10 '14 at 17:57
  • This is documented in many places and examples. For example: https://demo.ocpu.io/appdemo/www/chain.html or https://www.opencpu.org/posts/opencpu-release-1-4-4/ – Jeroen Ooms Sep 11 '14 at 18:02