summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprashantsinalkar2019-06-28 21:33:27 +0530
committerprashantsinalkar2019-06-28 21:33:27 +0530
commitcf1750ccd07a511ffa04c22004d57044d0741aef (patch)
treedcc11518968bf78676cc65dcf146a08e49f9a34b
parent67c6919a8c7058b642dcb3e663c1de5c315377d5 (diff)
downloadR_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.R37
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)
+}
+