Hi everyone,
I've been trying to solve this problem for weeks. I want to send data from my Web app to the Rook server and then have R do some computations with the data I send to it, then I want Rook to send the results back to the Web App where the app will display it. I've only gotten as far as my Rook receiving the given parameters and displaying it on the R console.
Question: How do I send data from Rook server back to Web App?
Here's my ajax function from the web app:
$.ajax({
type: 'POST',
dataType:"json",
data: { 'name : name, 'age' : age },
success: function(data){
alert("SUCCESS" + data);
},
error: function(){
alert(" AJAX ERROR ");
}
}); // END AJAX Call
library(Rook)
s <- Rhttpd$new()
s$start(quiet=TRUE)
s$add(
name ="compute",
app = function(env) {
req = Request$new(env)
res = Response$new()
name = unlist(strsplit(req$params()$name, ","))
age = unlist(strsplit(req$params()$age, ","))
results = list()
results$fac = facets
results$age = age
#print() only displays to console, but I want to send this to my webapp
print(toJSON(results)) #prints results to console
res$finish()
}
)
s$browse("summarize")
Sorry if the formatting looks bad, any input would be greatly appreciated! What I'm looking for is probably just one line - something that can send the data to my ajax function.