diff options
author | prashantsinalkar | 2019-06-29 15:42:49 +0530 |
---|---|---|
committer | prashantsinalkar | 2019-06-29 15:42:49 +0530 |
commit | 58f7c7719aa8c64ecf84998207756af6b6a4a7c2 (patch) | |
tree | 85f4306bfcda6e50e08481092b9559b4311538ca | |
parent | cf1750ccd07a511ffa04c22004d57044d0741aef (diff) | |
download | R_on_Cloud_Web_API-58f7c7719aa8c64ecf84998207756af6b6a4a7c2.tar.gz R_on_Cloud_Web_API-58f7c7719aa8c64ecf84998207756af6b6a4a7c2.tar.bz2 R_on_Cloud_Web_API-58f7c7719aa8c64ecf84998207756af6b6a4a7c2.zip |
added dynamic file names and formated the code
-rw-r--r-- | plumber.R | 39 |
1 files changed, 23 insertions, 16 deletions
@@ -4,34 +4,41 @@ library(jsonlite) library(readr) library(futile.logger) library(tryCatchLog) +library(ggplot2) #* Echo back the input #* @param msg The message to echo #* @get /echo -function(msg=""){ - list(msg = paste0("The message is: '", msg, "'")) +function(msg="") +{ + list(msg = paste0("The message is: '", msg, "'")) } #* Plot a histogram #* @png #* @get /plot -function(){ - rand <- rnorm(100) - hist(rand) +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) +function(code="", user_id="") +{ + InputFile <- paste("/tmp/",user_id,"/",user_id,".R", sep="") + OutputFile <- paste("/tmp/",user_id,"/",user_id,".txt", sep="") + RunInputFile <- paste("Rscript", InputFile, sep=" ") + fileConn<-file(InputFile) + writeLines(code, fileConn) + close(fileConn) + ro <- system(RunInputFile, intern = TRUE) + fileConn<-file(OutputFile) + writeLines(ro, fileConn) + close(fileConn) + ro <- read_file(OutputFile) + r<- list(status = "SUCCESS", code = "200", output = ro) + return (r) } |