# Dynamically Provisioning R Libraries with renv

**URL:** <https://support.openanalytics.eu/t/dynamically-provisioning-r-libraries-with-renv/3057>\
**Category:** ShinyProxy\
**Created:** [January 24, 2025, 3:27pm UTC](https://support.openanalytics.eu/t/dynamically-provisioning-r-libraries-with-renv/3057 "2025-01-24T15:27:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asadow](https://support.openanalytics.eu/user_avatar/support.openanalytics.eu/asadow/32/930_2.png) [@asadow](https://support.openanalytics.eu/u/asadow)\
**Post date:** [January 24, 2025, 3:27pm UTC](https://support.openanalytics.eu/t/dynamically-provisioning-r-libraries-with-renv/3057/1 "2025-01-24T15:27:07Z")

</div>

Is it possible to run apps through shinyproxy with a host renv cache mount?

```auto
# the location of the renv cache on the host machine
RENV_PATHS_CACHE_HOST=/opt/local/renv/cache

# where the cache should be mounted in the container
RENV_PATHS_CACHE_CONTAINER=/renv/cache

# run the container with the host cache mounted in the container
docker run --rm \
    -e "RENV_PATHS_CACHE=${RENV_PATHS_CACHE_CONTAINER}" \
    -v "${RENV_PATHS_CACHE_HOST}:${RENV_PATHS_CACHE_CONTAINER}" \
    -p 14618:14618 \
    R -s -e 'renv::restore(); shiny::runApp(host = "0.0.0.0", port = 14618)'

```

[Using renv with Docker • renv](https://rstudio.github.io/renv/articles/docker.html#dynamically-provisioning-r-libraries-with-renv)

---

<div class="post-metadata">

**Author:** ![asadow](https://support.openanalytics.eu/user_avatar/support.openanalytics.eu/asadow/32/930_2.png) [@asadow](https://support.openanalytics.eu/u/asadow)\
**Post date:** [January 24, 2025, 3:30pm UTC](https://support.openanalytics.eu/t/dynamically-provisioning-r-libraries-with-renv/3057/2 "2025-01-24T15:30:22Z")

</div>

Would this be the way?

Dockerfile

```auto
FROM openanalytics/r-ver:4.4.2

# Prepare system libraries and R environment
RUN apt-get update && apt-get install --no-install-recommends -y \
    libpq-dev \
    && rm -rf /var/lib/apt/lists/*

# Set up working directory and permissions
WORKDIR /project
COPY . /project
RUN chown -R nobody:nogroup /project

# Install renv and prepare the R environment for Shiny
RUN R -e "install.packages('remotes'); remotes::install_version('renv', '1.0.11');"
ENV RENV_PATHS_CACHE=/renv/cache

USER nobody
CMD ["R", "-e", "renv::restore(); shiny::runApp('/project')"]

```

application.yml

```auto
proxy:
  title: ShinyProxy Example
  port: 8080
  docker:
    url: http://localhost:2375
    internal-networking: true
  specs:
    - id: app1
      display-name: Application 1
      description: An application with RENV
      container-cmd: ["R", "-e", "renv::restore(); shiny::runApp('/project')"]
      container-env:
        RENV_PATHS_CACHE: "/renv/cache"
      docker-volumes:
        - "/path/on/host/renv/cache:/renv/cache"

```

---

<div class="post-metadata">

**Author:** ![tdekoninck](https://support.openanalytics.eu/user_avatar/support.openanalytics.eu/tdekoninck/32/1079_2.png) [@tdekoninck](https://support.openanalytics.eu/u/tdekoninck)\
**Post date:** [February 13, 2025, 7:43am UTC](https://support.openanalytics.eu/t/dynamically-provisioning-r-libraries-with-renv/3057/3 "2025-02-13T07:43:17Z")

</div>

Hi, you can mount volumes using the `container-volumes` option, see [Configuration | ShinyProxy](https://shinyproxy.io/documentation/configuration/#container-volumes)
