diff options
author | prashantsinalkar | 2019-06-28 21:33:27 +0530 |
---|---|---|
committer | prashantsinalkar | 2019-06-28 21:33:27 +0530 |
commit | cf1750ccd07a511ffa04c22004d57044d0741aef (patch) | |
tree | dcc11518968bf78676cc65dcf146a08e49f9a34b | |
parent | 67c6919a8c7058b642dcb3e663c1de5c315377d5 (diff) | |
download | R_on_Cloud_Web_API-cf1750ccd07a511ffa04c22004d57044d0741aef.tar.gz R_on_Cloud_Web_API-cf1750ccd07a511ffa04c22004d57044d0741aef.tar.bz2 R_on_Cloud_Web_API-cf1750ccd07a511ffa04c22004d57044d0741aef.zip |
added plumber file
-rw-r--r-- | plumber.R | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/plumber.R b/plumber.R new file mode 100644 index 0000000..580c018 --- /dev/null +++ b/plumber.R @@ -0,0 +1,37 @@ +# plumber.R +library(plumber) +library(jsonlite) +library(readr) +library(futile.logger) +library(tryCatchLog) + +#* Echo back the input +#* @param msg The message to echo +#* @get /echo +function(msg=""){ + list(msg = paste0("The message is: '", msg, "'")) +} + +#* Plot a histogram +#* @png +#* @get /plot +function(){ + rand <- rnorm(100) + hist(rand) +} + +#* @serializer unboxedJSON +#* @post /rscript +function(code=""){ + fileConn<-file("input.R") + writeLines(code, fileConn) + close(fileConn) + ro <- system("Rscript input.R", intern = TRUE) + fileConn<-file("output.txt") + writeLines(ro, fileConn) + close(fileConn) + ro <- read_file("output.txt") + r<- list(status = "SUCCESS", code = "200", output = ro) + return (r) +} + |