This microservice is part of the microservice pipline in inseri. The service provides the possibility to use/create R code, use it to transform a response received by an API call into the needed data structure and pass the result to another inseri app.
- Python 3
- R
- Create a virtual environment
- Activate your created virtual environment
pip3 install -r requirements.txt
- Run with
python3 r-task.py
- Go to http://localhost:50002
- Build the image:
[sudo] docker build -t nieine/microservice-r-task .
- Run the container:
[sudo] docker run -p 50002:50002 nieine/microservice-r-task
- Go to http://localhost:50002
If the service is running, you can POST a body with JSON data from any application.
Body:
{
"datafile": "[The name of the JSON file]",
"data": "[The content of the JSON file]",
"codefile": "[The name of the R file]",
"code": "[The content of the R file]"
}
Response:
{
"output": "...",
}
E.g.:
{
"datafile": "yourData.json",
"data": "{\n \"message\": \"Hello World!\"\n}\n",
"codefile": "yourCode.R",
"code": "suppressMessages(library(\"jsonlite\"))\n\nreadJson <- function(inputFile) {\n json <- fromJSON(inputFile)\n dataFrame <- as.data.frame(json)\n return(as.character(dataFrame$message))\n}\n\nreadJson(\"yourData.json\")\n"
}
{
"output": "Hello World!"
}
- Build the image:
[sudo] docker build -t nieine/microservice-r-task:YYYY-MM-DD .
- Push the image:
[sudo] docker push nieine/microservice-r-task:YYYY-MM-DD
Currently, the below-listed R packages are installed. To add more packages, re-build the Docker image after adding the package to the Dockerfile as follows:
RUN R -e 'install.packages("zoo", repos = "http://cran.rstudio.com/")'
- data.table
- ggivs
- ggmap
- graphics
- htmlwidgets
- diagrammeR
- DT
- dygraphs
- leaflet
- network3D
- threeJS
- jsonlite
- lubridate
- maps
- maps
- maptools
- ngram
- quantmod
- rjson
- sp
- tidyverse
- dplyr
- forcats
- ggplot2
- purrr
- readr
- stringr
- tibble
- tidyr
- XML
- xtable
- xts
- zoo