init R support

This commit is contained in:
Minghe Huang
2017-11-23 01:41:12 +08:00
parent 624f0dba39
commit dbefe38dd6
3 changed files with 24 additions and 0 deletions

10
images/R/Dockerfile Normal file
View File

@@ -0,0 +1,10 @@
FROM r-base
RUN echo 'install.packages(c("jug", "jsonlite"), repos="http://cran.us.r-project.org", dependencies=TRUE)' > /tmp/packages.R \
&& Rscript /tmp/packages.R
COPY . /usr/local/src/fx
WORKDIR /usr/local/src/fx
CMD ["Rscript", "app.R"]
EXPOSE 3000

11
images/R/app.R Normal file
View File

@@ -0,0 +1,11 @@
library(jug)
library(jsonlite)
source('./fx.R')
jug() %>%
post("/", function(req, res, err) {
input <- fromJSON(req$body)
fx(input)
}) %>%
simple_error_handler_json() %>%
serve_it(port = 3000)

3
images/R/fx.R Normal file
View File

@@ -0,0 +1,3 @@
fx <- function(input) {
return (strtoi(input$a) + strtoi(input$b))
}