diff options
Diffstat (limited to 'plumber.R')
-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) +} + |