Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renv library not recognized in 4.2.2-build? #30

Open
tomcardoso opened this issue Dec 11, 2024 · 5 comments
Open

renv library not recognized in 4.2.2-build? #30

tomcardoso opened this issue Dec 11, 2024 · 5 comments

Comments

@tomcardoso
Copy link

Hey there, I've been trying to get this docker image to work today, but it looks like despite renv::restore() being called in your Dockerfile, once I have a project running, the very first library(pkg) doesn't work. R says the package can't be found. If I run an renv::status(), it tells me the packages listed the lockfile aren't installed.

I thought it might be because I had renv in my R project and it was getting confused about library paths, so I deleted the renv folder and files – but I'm still running into this issue. Any ideas? Could this be a pathing issue?

FWIW, I'm using renv 1.0.11 and R 4.2.2. I'm also loading heroku-docker-r through my own docker image, listed here: https://github.com/tomcardoso/docker-r-shiny-map/.

@virtualstaticvoid
Copy link
Owner

Hi @tomcardoso

I had a look at your project, tomcardoso/docker-r-shiny-map, and noticed that renv does get activated and installs the packages during the GitHub Actions build.

image

Running the built container image seems to work too; I was able to load packages which are included in the renv.lock file. E.g. shiny.

$ docker run -it --rm ghcr.io/tomcardoso/docker-r-shiny-map:latest R -e "library(shiny)"

R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

...

- Project '/app' loaded. [renv 1.0.11]
- The project is out-of-sync -- use `renv::status()` for details.
> library(shiny)
> 
> 

renv reports "The project is out-of-sync", and running renv::status() shows the packages are installed, but not used; which is expected since the project doesn't have any R files as such.

$ docker run -it --rm ghcr.io/tomcardoso/docker-r-shiny-map:latest R -e "renv::status()"

R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

...

- Project '/app' loaded. [renv 1.0.11]
- The project is out-of-sync -- use `renv::status()` for details.
> renv::status()
The following package(s) are in an inconsistent state:

 package           installed recorded used
 base64enc         y         y        n   
 bit               y         y        n   
 bit64             y         y        n   
 bslib             y         y        n   
 cachem            y         y        n   

...

Could you provide more details on the error you are getting please.

@virtualstaticvoid
Copy link
Owner

I forked the docker-r-shiny-map repository and noticed that the Dockerfile references v4.4.2, so I also tested with v4.2.2 (as per title of this issue) and wasn't able to replicate the issue either. See pull request and build.

The only possible explanation I can think of is when running the container the working directory is not /app, and thus renv/activate.R isn't executed.

@tomcardoso
Copy link
Author

Sorry for the delay – holidays, etc. Very weird. I might circle back to trying this again down the line (I deployed on shinyapps.io instead when I hit this wall last year)… the fact you can't reproduce it is probably a good sign that there's something wrong on my end, though.

@tomcardoso
Copy link
Author

tomcardoso commented Jan 7, 2025

I just tried spinning the Heroku app back up. Here's what I get, FWIW (ignore the commented out stuff and print statements, that was me doing some basic debugging):

Jan 07 15:19:06 map heroku/web.1 Starting process with command `/usr/bin/R --no-save --gui-none -f /app/run.R`
Jan 07 15:19:07 map heroku/web.1 State changed from starting to crashed
Jan 07 15:19:07 map heroku/web.1 Process exited with status 1
Jan 07 15:19:07 map app/web.1 R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
Jan 07 15:19:07 map app/web.1 Copyright (C) 2024 The R Foundation for Statistical Computing
Jan 07 15:19:07 map app/web.1 Platform: x86_64-pc-linux-gnu
Jan 07 15:19:07 map app/web.1 R is free software and comes with ABSOLUTELY NO WARRANTY.
Jan 07 15:19:07 map app/web.1 You are welcome to redistribute it under certain conditions.
Jan 07 15:19:07 map app/web.1 Type 'license()' or 'licence()' for distribution details.
Jan 07 15:19:07 map app/web.1 R is a collaborative project with many contributors.
Jan 07 15:19:07 map app/web.1 Type 'contributors()' for more information and
Jan 07 15:19:07 map app/web.1 'citation()' on how to cite R or R packages in publications.
Jan 07 15:19:07 map app/web.1 Type 'demo()' for some demos, 'help()' for on-line help, or
Jan 07 15:19:07 map app/web.1 'help.start()' for an HTML browser interface to help.
Jan 07 15:19:07 map app/web.1 Type 'q()' to quit R.
Jan 07 15:19:07 map app/web.1 > 
Jan 07 15:19:07 map app/web.1 > # renv::status()
Jan 07 15:19:07 map app/web.1 > .libPaths()
Jan 07 15:19:07 map app/web.1 [1] "/app/R/site-library"           "/usr/local/lib/R/site-library"
Jan 07 15:19:07 map app/web.1 [3] "/usr/lib/R/site-library"       "/usr/lib/R/library"           
Jan 07 15:19:07 map app/web.1 > print('run.R')
Jan 07 15:19:07 map app/web.1 [1] "run.R"
Jan 07 15:19:07 map app/web.1 > 
Jan 07 15:19:07 map app/web.1 > library(shiny)
Jan 07 15:19:07 map app/web.1 Error in library(shiny) : there is no package called ‘shiny’
Jan 07 15:19:07 map app/web.1 Execution halted

And this is the Heroku build log:

=== Fetching app code
=== Building web (Dockerfile)
Sending build context to Docker daemon  29.24MBStep 1/4 : FROM ghcr.io/tomcardoso/docker-r-shiny-map:latest
latest: Pulling from tomcardoso/docker-r-shiny-map
7478e0ac0f23: Pulling fs layer
a587c4c56368: Pulling fs layer
a6ced5976107: Pulling fs layer
7da741f6b5eb: Pulling fs layer
2cba01230ac0: Pulling fs layer
250c9f186d16: Pulling fs layer
33587424f6c7: Pulling fs layer
abb22dd8e1d1: Pulling fs layer
4f4fb700ef54: Pulling fs layer
8ad919b43f41: Pulling fs layer
7da741f6b5eb: Waiting
be9e2f0bf257: Pulling fs layer
2cba01230ac0: Waiting
250c9f186d16: Waiting
546b2542f670: Pulling fs layer
33587424f6c7: Waiting
abb22dd8e1d1: Waiting
4f4fb700ef54: Waiting
be9e2f0bf257: Waiting
546b2542f670: Waiting
a587c4c56368: Download complete
7da741f6b5eb: Verifying Checksum
7da741f6b5eb: Download complete
2cba01230ac0: Verifying Checksum
2cba01230ac0: Download complete
250c9f186d16: Verifying Checksum
250c9f186d16: Download complete
abb22dd8e1d1: Verifying Checksum
abb22dd8e1d1: Download complete
4f4fb700ef54: Verifying Checksum
4f4fb700ef54: Download complete
7478e0ac0f23: Verifying Checksum
7478e0ac0f23: Download complete
8ad919b43f41: Download complete
33587424f6c7: Verifying Checksum
33587424f6c7: Download complete
546b2542f670: Verifying Checksum
546b2542f670: Download complete
be9e2f0bf257: Verifying Checksum
be9e2f0bf257: Download complete
7478e0ac0f23: Pull complete
a587c4c56368: Pull complete
a6ced5976107: Pull complete
7da741f6b5eb: Pull complete
2cba01230ac0: Pull complete
250c9f186d16: Pull complete
33587424f6c7: Pull complete
abb22dd8e1d1: Pull complete
4f4fb700ef54: Pull complete
8ad919b43f41: Pull complete
be9e2f0bf257: Pull complete
546b2542f670: Pull complete
Digest: sha256:6c1da32e59c250153210e3621dece3db9642fa3bc6a454b5562afb41eac986c2
Status: Downloaded newer image for ghcr.io/tomcardoso/docker-r-shiny-map:latest
 ---> d4fac637c0fc
Step 2/4 : COPY . /app
 ---> ee83493a192a
Step 3/4 : ENV PORT=8080
 ---> Running in 25979d6c3943
Removing intermediate container 25979d6c3943
 ---> bede00c43fd5
Step 4/4 : CMD ["/usr/bin/R", "--no-save", "--gui-none", "-f", "/app/run.R"]
 ---> Running in f07919e52f2e
Removing intermediate container f07919e52f2e
 ---> 1d9988956f9c
Successfully built 1d9988956f9c
Successfully tagged 3afb1af124a0e0ca03cd73b45fb0a737956848c9:latest
=== Pushing web (Dockerfile)
Tagged image "3afb1af124a0e0ca03cd73b45fb0a737956848c9" as "registry.heroku.com/map/web"
Using default tag: latest
The push refers to repository [registry.heroku.com/map/web]
adb2f4509c94: Preparing
21dec40bdf53: Preparing
5f70bf18a086: Preparing
5f70bf18a086: Preparing
5f70bf18a086: Preparing
e192ebc2788d: Preparing
34e6a5d8a87f: Preparing
5f70bf18a086: Preparing
5ae40c457f72: Preparing
ce923cc9993e: Preparing
018a2c2cc597: Preparing
2f34a2eb72ef: Preparing
8c06dfad64f7: Preparing
a27eab021c8d: Preparing
1b9873c0c809: Preparing
2573e0d81582: Preparing
8c06dfad64f7: Waiting
a27eab021c8d: Waiting
5ae40c457f72: Waiting
1b9873c0c809: Waiting
ce923cc9993e: Waiting
018a2c2cc597: Waiting
2f34a2eb72ef: Waiting
2573e0d81582: Waiting
21dec40bdf53: Layer already exists
34e6a5d8a87f: Layer already exists
5f70bf18a086: Layer already exists
e192ebc2788d: Layer already exists
ce923cc9993e: Layer already exists
5ae40c457f72: Layer already exists
018a2c2cc597: Layer already exists
2f34a2eb72ef: Layer already exists
a27eab021c8d: Layer already exists
1b9873c0c809: Layer already exists
8c06dfad64f7: Layer already exists
2573e0d81582: Layer already exists
adb2f4509c94: Pushed
latest: digest: sha256:98a0de120fdd49cac6cf844062df88463ebb8f6461bff3310cc11a777ef5b4f4 size: 3668

I realize these aren't super helpful on their own, but maybe you'll see something I don't?

@virtualstaticvoid
Copy link
Owner

virtualstaticvoid commented Jan 12, 2025

Hi @tomcardoso

Unfortunately, I'm still not able to replicate the issue based off this new information.

I created docker-r-shiny-map-demo as an example application to use for the test, based on what I understand from your description. I tested using the container image from your repo and the image from my fork.

FROM ghcr.io/tomcardoso/docker-r-shiny-map:latest

COPY . /app

CMD ["/usr/bin/R", "--no-save", "--gui-none", "-f", "/app/run.R"]

Please take a look at the demo project configuration and compare it to your project. Hopefully this helps.

EDIT: I assumed that since the renv directory is included in the container image, it need not be included in the demo application.

If you have included the renv directory in your application project, make sure it's excluded in the .dockerignore file, so that the container's directory doesn't get corrupted when the COPY . /app command is run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants