# Non-root user apps and \`renv\`

**URL:** <https://support.openanalytics.eu/t/non-root-user-apps-and-renv/2732>\
**Category:** ShinyProxy\
**Created:** [February 21, 2024, 11:00pm UTC](https://support.openanalytics.eu/t/non-root-user-apps-and-renv/2732 "2024-02-21T23:00:57Z")\
**Posts on this page:** 2\
**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:** [February 21, 2024, 11:00pm UTC](https://support.openanalytics.eu/t/non-root-user-apps-and-renv/2732/1 "2024-02-21T23:00:57Z")

</div>

Was anyone able to get `renv` to work successfully with an app whose Dockerfile changes the user to one that is not root?

Whenever I try to add `renv` set-up and commands, I get errors on start-up or `renv` starts downloading packages. E.g. after `docker run -p 3838:3838 my-image`,

```auto
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

# Bootstrapping renv 1.0.2 [sha: 464e042] ------------------------------------
- Downloading renv ... OK
- Installing renv ... ^COK

```

Dockerfile:

```auto
FROM rocker/shiny-verse:4.2.2

## For igraph from dm (GH issue: may become Suggested)
RUN apt-get -y update && apt-get -y install \
    libglpk-dev \
    libgmp3-dev \
    libxml2-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/

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

RUN echo "local(options(shiny.port = 3838, shiny.host = '0.0.0.0'))" > /usr/local/lib/R/etc/Rprofile.site

RUN mkdir /home/app
WORKDIR /home/app
## Copy application code
COPY shiny .
## Install dependencies
RUN Rscript -e 'renv::restore()'

## Set up non-root user
RUN addgroup --system app \
    && adduser --system --ingroup app app
RUN chown app:app -R .
USER app

EXPOSE 3838

CMD ["R", "-e", "shiny::runApp('/home/app/')"]

```

---

<div class="post-metadata">

**Author:** ![kramerrs](https://support.openanalytics.eu/user_avatar/support.openanalytics.eu/kramerrs/32/793_2.png) [@kramerrs](https://support.openanalytics.eu/u/kramerrs)\
**Post date:** [March 1, 2024, 5:22pm UTC](https://support.openanalytics.eu/t/non-root-user-apps-and-renv/2732/2 "2024-03-01T17:22:15Z")

</div>

R and renv have complicated search paths for libraries. I use renv in a Dockerfile, as root it just seems to just work, but I am not sure where the libraries are getting installed in this instance. I suspect they are in the /home/root/… path prefix.

There are different options for renv. The one comes to mind would be to activate a local library prior to restoring, then run the command from that project. renv::activate() then renv::restore().

I would be interested in what you find. I haven’t found a good way to have renv directly install packages into the system directory, though it is possible to create a library with the above activate/restore methodology and copy/link into the system directory. That works for sure.
