init R support
This commit is contained in:
10
images/R/Dockerfile
Normal file
10
images/R/Dockerfile
Normal 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
11
images/R/app.R
Normal 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
3
images/R/fx.R
Normal file
@@ -0,0 +1,3 @@
|
||||
fx <- function(input) {
|
||||
return (strtoi(input$a) + strtoi(input$b))
|
||||
}
|
||||
Reference in New Issue
Block a user