Hello shiny developers,
As you see the example Dockerfile below, third RUN layer installs R packages. If you have to work many R packages for the apps, the installation of all packages takes too much time at this step.
I thought if we have a virtual environment for our project, we can skip this layer without wasting too much time. That’s why, I looked at renv package to create a virtual environment and implement it into a Dockerfile.
I arrange the docker file like on the documentation. However, I run the container and it doesn’t read all libraries from virtual environment I created , it reads the package list from lockfile and starts downloading and installing all packages step by step I need.
The Example Dockerfile in the Documantation
FROM openanalytics/r-base
LABEL maintainer "Tobias Verbeke <tobias.verbeke@openanalytics.eu>"
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
libssl1.0.0
# system library dependency for the euler app
RUN apt-get update && apt-get install -y \
libmpfr-dev
# basic shiny functionality
RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cloud.r-project.org/')"
# install dependencies of the euler app
RUN R -e "install.packages('Rmpfr', repos='https://cloud.r-project.org/')"
# copy the app to the image
RUN mkdir /root/euler
COPY euler /root/euler
COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/root/euler')"]
Dockerfile of my project
FROM openanalytics/r-base
LABEL maintainer "Tobias Verbeke <tobias.verbeke@openanalytics.eu>"
# https://packagemanager.posit.co/client/#/repos/2/packages/A3
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
nano \
make \
automake \
pandoc \
pandoc-citeproc \
libicu-dev \
zlib1g-dev \
libcurl4-openssl-dev \
libssl-dev \
libfontconfig1-dev \
libfreetype6-dev \
libfribidi-dev \
libxml2-dev \
libharfbuzz-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libglpk-dev \
libgmp3-dev \
libpq-dev \
libcairo2-dev \
libxt-dev \
libssh2-1-dev \
libssl1.1 \
libmpfr-dev
# install shiny packages
RUN R -e "install.packages(c('renv'), repos='https://cloud.r-project.org/')"
# Create Directory
RUN mkdir /root/Project
# copy the app to the image
COPY Project /root/Project
# copy all virtual environment files
COPY renv.lock renv.lock
COPY renv renv
COPY .Rprofile .Rprofile
EXPOSE 3838
CMD ["R", "-e", "renv::restore(); shiny::runApp('/root/Project')"]
Building Dockerfile and testing it
# Build the image from dockerfile I created
docker build -t 127.0.0.1:5000/renv/test .
# Run a container and check the shiny app. Does the image works or not?
docker run -p 4040:3838 127.0.0.1:5000/renv/test
What is the best way to work with Virtual Environment and ShinyProxy and how we should have a dockerfile to make this?
Thanks in advance.