Definite guide for Shiny applications with Renv (2024)

Tobias Schmidt published on
1 min, 159 words

Tags: R

Definite guide for Shiny applications with Renv (2024)

Setup

It happens more often than one might think that you need an R/Shiny server dockerized. Additionally, it is required to track the dependencies of the project with Renv. Although multiple tutorials/manuals exists, none of them worked by themself and only a merged version worked.

FROM rocker/shiny:4.1.1 as shiny
RUN apt-get update && apt-get install -y libpq-dev zlib1g-dev libgdal-dev librsvg2-dev libeigen3-dev libopenbabel-dev libopenbabel6 curl fontconfig
ENV RENV_VERSION v1.0.5
RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))"
RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')"
RUN rm -rf /srv/shiny-server/*

WORKDIR /srv/shiny-server/APPLICATION
ENV RENV_PATHS_LIBRARY renv/library
COPY renv.lock renv.lock
COPY renv/activate.R renv/activate.R
COPY .Rprofile .Rprofile
COPY APPLICATION.Rproj APPLICATION.Rproj
RUN R -e 'renv::restore()'
RUN R -e 'renv::isolate()'

It was elementary to call renv::isolate() at the end of the docker build.