Using dockerfile cache while installing R packages with renv::restore()

Hello Shiny developers,

I'm trying to deploy a shiny app by using dockerfile. Installing packages in building dockerfile process takes too long time as you know that.

If you have to build dockerfile again, you have to wait for it and waste your time. It only takes your time when the process is in the renv::restore() step. However, docker uses caches to skip other steps which is old completed steps in the next building processes.

Is there any way to use caches for renv::restore() step ???

FROM openanalytics/r-base

LABEL maintainer "Ekrem Bayar <...>"

# 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 \
    cmake \
    gcc \
    g++ \
    gfortran \
    libquantlib0* \
    # rmarkdown
    libicu-dev \
    # shinyverse
    zlib1g-dev \
    # tidyverse  
    libcurl4-openssl-dev \
    libssl-dev \
    libfontconfig1-dev \
    libfreetype6-dev \
    libfribidi-dev \
    libxml2-dev \
    libharfbuzz-dev \
    libjpeg-dev \
    libpng-dev \
    libtiff-dev \
    # highcharter
    libglpk-dev \
    libgmp3-dev \
    # RPostgres
    libpq-dev \
    # Diğer
    libcairo2-dev \
    libxt-dev \
    libssh2-1-dev \
    libssl1.1 \
   libmpfr-dev \
    openjdk-7-* \
    default-jre \
    default-jre-headless \
    default-jdk \
    libgdal-dev \
    libproj-dev \
    liblapack-dev \
    # R versiyonunu yükseltmek için
    r-base

#RUN add-apt-repository ppa:marutter/c2d4u && apt-get update
RUN R CMD javareconf

#RUN R -e "install.packages(c('rJava'), repos='https://cloud.r-project.org/')"

#RUN apt-get install -y \    
#    libgdal-dev libproj-dev \
#    r-cran-rjava \
#    && apt-get clean \
#    && rm -rf /var/lib/apt/lists/

# Install R Packages
RUN R -e "install.packages(c('renv', 'rJava'), repos='https://cloud.r-project.org/')"
#RUN R -e "install.packages(c('renv', 'rJava', 'Matrix', 'MatrixModels'), repos='https://cloud.r-project.org/')"

RUN apt-get update && apt-get install -y \
   libmagick++-dev

RUN apt-get update && apt-get install -y netbase
RUN apt-get install -y chromium-browser

# Uygulama dosyaları root'un altına kopyalanır
RUN mkdir /root/CMI
COPY cmi_shiny /root/CMI

RUN mkdir -p renv
COPY renv.lock renv.lock
COPY .Rprofile .Rprofile
COPY renv/activate.R renv/activate.R
COPY renv/settings.dcf renv/settings.dcf

# change default location of cache to project folder
RUN mkdir renv/.cache
ENV RENV_PATHS_CACHE renv/.cache
ENV RENV_PATHS_LIBRARY renv/library


# restore 
RUN R -e "options(timeout = 400);renv::restore()"

EXPOSE 3838

CMD ["R", "-e", "shiny::runApp('/root/CMI')"]

Thanks in advance.

The article at Using renv with Docker • renv may be helpful.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.