I am trying to deploy plumber API to Azure web service (as web app) using instructions from this site https://veerlevanleemput.medium.com/hosting-a-r-plumber-api-using-azure-app-service-4e78936787cf
I have problem with adding python and reticulate in the docker file and using it in plumber.R file.
Here is my Dockerfile (adjusted following this Stack overflow QA: Running the R package reticulate in Docker environment):
# Dockerfile
FROM rocker/r-base:4.2.1
# install the linux libraries needed for plumber
RUN apt-get update --fix-missing \
&& apt-get install -y \
ca-certificates \
build-essential \
libprotobuf-dev \
protobuf-compiler \
cmake \
libglib2.0-0 \
libxext6 \
libsm6 \
libxrender1 \
libcurl4-gnutls-dev \
libxml2-dev \
libsndfile1 \
libx11-dev \
libatlas-base-dev \
libgtk-3-dev \
libboost-python-dev \
libsodium-dev \
ffmpeg \
python3-audioread \
libssl-dev \
openssl \
python3-openssl \
pkg-config
# RUN apt-get update -qq && apt-get install -y \
# libssl-dev \
# libcurl4-gnutls-dev \
# libsodium-dev
# create the application folder
RUN mkdir -p ~/application
# copy everything from the current directory into the container
COPY "/" "application/"
WORKDIR "application/"
# open port 8080 to traffic
EXPOSE 8080
# install packages
RUN R -e "install.packages('plumber')"
RUN R -e "install.packages('exuber')"
RUN R -e "install.packages('data.table')"
RUN R -e "install.packages('quarks')"
RUN R -e "install.packages('theft')"
RUN R -e "install.packages('tvgarch')"
RUN R -e "install.packages('mlr3')"
RUN R -e "install.packages('utils')"
RUN R -e "install.packages('remotes')"
RUN R -e "remotes::install_github('https://github.com/MislavSag/finfeatures')"
RUN R -e "remotes::install_github('https://github.com/mlr-org/mlr3extralearners')"
# Install Autogluon
RUN R -q -e 'reticulate::install_miniconda()'
RUN R -q -e 'reticulate::conda_create(envname = "r-tsfel")'
RUN R -q -e 'reticulate::conda_install(envname = "r-tsfel", packages = "tsfel", pip = TRUE)'
# Install tsfel
RUN R -q -e 'reticulate::install_miniconda()'
RUN R -q -e 'reticulate::conda_create(envname = "r-tsfel", packages = c("python=3.8.13"))'
RUN R -q -e 'reticulate::conda_install(envname = "r-tsfel", packages = "tsfel", pip = TRUE)'
## Modify Rprofile
RUN R -e 'write("reticulate::use_condaenv(\"r-tsfel\", required = TRUE)",file=file.path(R.home(),"etc","Rprofile.site"),append=TRUE)'
RUN R -e 'write("reticulate::import(\"tsfel\")",file=file.path(R.home(),"etc","Rprofile.site"),append=TRUE)'
# install python and packages
# RUN apt-get -y install python3 python3-venv python3-pip
# RUN python3 -m venv /home/rstudio/venv
# RUN /home/rstudio/venv/bin/pip3 install --upgrade pip setuptools wheel
# RUN /home/rstudio/venv/bin/pip3 install tsfel
# when the container starts, start the main R script
ENTRYPOINT ["Rscript", "execute_plumber.R"]
Plumber.R file (I have only kept the function that is not working):
# plumber.R
# libraries
library(plumber)
library(exuber)
library(finfeatures)
library(runner)
library(reticulate)
#* mlr3 hft model v2 dsf
#* @param open open prices
#* @param high high prices
#* @param low low prices
#* @param close close prices
#* @param volume volume prices
#* @post /modeltsfel
function(open, high, low, close, volume) {
# create OHLCV
df = cbind.data.frame(symbol = "TEST",
date = seq.Date(from = Sys.Date() - 10, length.out = length(close), by = 1),
open, high, low, close, volume)
ohlcv <- Ohlcv$new(df)
RollingTheftInit = RollingTheft$new(windows = 240,
workers = 1L,
at = nrow(ohlcv$X),
lag = 0L,
na_pad = TRUE,
simplify = FALSE,
features_set = "tsfel")
tsfel_features <- RollingTheftInit$rolling_function(ohlcv$X, 240, "close")
return(tsfel_features[, 5])
}
An finally here is my file that starts Docker:
# Execute plumber
plumber::plumb(file="plumber.R")$run(host = '0.0.0.0', port = 8080)
All functions work, except above one, in which I want to use python module through docker.