Skip to content

Commit bd2dfac

Browse files
committed
docs: add docs for using renv in projects
1 parent c22b71a commit bd2dfac

3 files changed

Lines changed: 78 additions & 33 deletions

File tree

docs/docs/10-users/60-sessions/guides/00-environments/20-create-environment-with-custom-packages-installed.md

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Create an environment with custom packages installed
22

3-
If you’d like a set of custom packages to be installed and ready to go when you (or anyone else) launches a session in your project, you can take advantage of Renku’s **code based environments**.
3+
If you’d like a set of custom packages to be installed and ready to go when you (or anyone else)
4+
launches a session in your project, you can take advantage of Renku’s **code based environments**.
45

5-
With Renku code based environments, you can point Renku to a code repository that contains an environment definition file, such as a `environment.yml`, `requirements.txt`, or `pyproject.toml`, and Renku will build a custom environment for your session for you!
6+
With Renku code based environments, you can point Renku to a code repository that contains an
7+
environment definition file, such as an `environment.yml`, `requirements.txt`, `pyproject.toml`, or
8+
`renv.lock`, and Renku will build a custom environment for your session for you!
69

710
This guide has 2 parts:
811

@@ -13,15 +16,7 @@ This guide has 2 parts:
1316

1417
## What kinds of environment definitions are supported?
1518

16-
RenkuLab’s code-based environments currently supports creating **Python** environments. Support for more languages is coming soon!
17-
18-
:::tip
19-
20-
Are you working in R? Support for R is coming soon. For now, for working with R please see
21-
[installing packages on the fly in your
22-
session](install-packages-on-the-fly-in-your-session).
23-
24-
:::
19+
RenkuLab’s code-based environments currently support creating **Python** and **R** environments.
2520

2621
### Defining a Python Environment
2722

@@ -144,13 +139,41 @@ Note that poetry version `1.8.3` will be used.
144139

145140
</details>
146141

147-
## Defining an R Environment
142+
### Defining an R Environment with renv
148143

149-
:::info
144+
Renku can build an R environment from an [`renv`](https://rstudio.github.io/renv/) lockfile.
145+
`renv` records the R packages used by your project in `renv.lock`; Renku uses this lockfile to
146+
restore those packages when building the session image.
150147

151-
This feature is coming soon. For now, please see [R](./install-packages-on-the-fly-in-your-session). ).
148+
To use `renv` with a code-based environment:
152149

153-
:::
150+
1. In your R project, install and initialize `renv` if you have not already done so:
151+
152+
```r
153+
install.packages("renv")
154+
renv::init()
155+
```
156+
157+
2. Install the packages your project needs as usual, for example:
158+
159+
```r
160+
install.packages(c("dplyr", "ggplot2", "shiny"))
161+
```
162+
163+
3. Snapshot the environment to update the lockfile:
164+
165+
```r
166+
renv::snapshot()
167+
```
168+
169+
4. Commit `renv.lock` at the root (top level) of the code repository. You should also commit the
170+
files created by `renv` that are meant to be shared with the project, such as `.Rprofile` and
171+
`renv/activate.R`.
172+
173+
When Renku builds the image, it restores the packages recorded in `renv.lock`. If a package requires
174+
system libraries that are not available in the build image, the build can fail. In that case,
175+
consider using a custom Docker image instead; see [How to use your own docker image for a Renku
176+
session](use-your-own-docker-image-for-renku-session).
154177

155178
## How to create a code-based environment for your Renku session
156179

@@ -162,7 +185,8 @@ repository](create-environment-with-custom-packages-private-code-repository).
162185

163186
:::
164187

165-
1. Make sure the code repository that contains your environment definition file is added to your Renku project.
188+
1. Make sure the code repository that contains your environment definition file is added to your
189+
Renku project.
166190
2. Create a **new session launcher**
167191
3. Select the **Create from code** option
168192

@@ -184,8 +208,10 @@ repository](create-environment-with-custom-packages-private-code-repository).
184208

185209
:::
186210

187-
5. Select the **Environment** **type** (Python, _more coming soon_)
188-
6. Select the **User interface** you’d like your session to have (VSCodium or Jupyterlab, _more coming soon_).
211+
5. Select the **Environment type**. Choose **Python** for Python environment definition files,
212+
or **R** for repositories that use `renv.lock`.
213+
6. Select the **User interface** you’d like your session to have, such as VSCodium/JupyterLab
214+
for Python environments or RStudio for R environments.
189215
7. Click **Next**
190216
8. Define the **name** of the Session Launcher
191217
9. Select the default **compute resources**
@@ -199,7 +225,9 @@ When the environment is built, you can launch your session.
199225

200226
## Updating a code-based environment
201227

202-
1. When you want to make changes to your environment (add new packages), first update the environment definition file in the code repository where the environment is defined.
228+
1. When you want to make changes to your environment (add new packages), first
229+
update the environment definition file in the code repository where the
230+
environment is defined.
203231
2. Then, rebuild the environment in RenkuLab:
204232
1. Click on the session launcher to open the session launcher side panel.
205233
2. Navigate to the **Session Environment** section.

docs/docs/10-users/60-sessions/guides/00-environments/25-create-environment-with-custom-packages-private-code-repository.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# Create an environment with custom packages from a private code repository (GitHub Actions)
22

3-
Would you like Renku to create an environment for you with the packages you need pre-installed? Renku can create a docker image for your Renku session for you based on a environment definition file in a code repository, such as a `environment.yml`, `requirements.txt`, or `pyproject.toml`.
3+
Would you like Renku to create an environment for you with the packages you need pre-installed?
4+
Renku can create a docker image for your Renku session for you based on an environment definition
5+
file in a code repository, such as an `environment.yml`, `requirements.txt`, `pyproject.toml`, or
6+
`renv.lock`.
47

5-
If your code repository is public, you can have Renku build this image directly as part of your project! See [How to create an environment with custom packages installed](create-environment-with-custom-packages-installed).
8+
If your code repository is public, you can have Renku build this image directly as part of your
9+
project! See [How to create an environment with custom packages
10+
installed](create-environment-with-custom-packages-installed).
611

7-
If your code repository is private, follow the instructions below.
12+
The instructions below are for _private_ code repositories that cannot use the
13+
automatic builds in RenkuLab.
814

915
## Create a GitHub action to build a docker image
1016

11-
1. First, make sure your code repository meets the requirements for Renku to build an image for you. See [What kinds of environment definitions are supported?](create-environment-with-custom-packages-installed)
17+
1. First, make sure your code repository meets the requirements for Renku to build an image for you.
18+
See [What kinds of environment definitions are
19+
supported?](create-environment-with-custom-packages-installed)
1220
2. In your GitHub code repository, in the upper menu, click on **Actions**.
1321

1422
<p class="image-container-l">
@@ -69,10 +77,14 @@ If your code repository is private, follow the instructions below.
6977
frontend: jupyterlab
7078
```
7179
72-
6. By default, the action defined above will create an image with JupyterLab as the front end. If you prefer a different front end, replace `jupyterlab` in the last line of the file with one of the following alternative front ends:
80+
6. By default, the action defined above will create an image with JupyterLab as
81+
the front end. If you prefer a different front end, replace `jupyterlab` in
82+
the last line of the file with one of the following alternative front ends:
7383
- `jupyterlab`: Web-based interactive development for Jupyter notebooks, code, and data.
7484
- `vscodium`: A freely-licensed version of Microsoft’s editor VS Code.
7585
- `ttyd`: A web-based terminal with a minimalist interface.
86+
- `rstudio`: RStudio Server for R projects.
87+
7688
7. Commit changes
7789

7890
## Add the built image to your Renku project

docs/docs/10-users/60-sessions/guides/00-environments/index.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@ environment is right for you, answer the following questions:
2020

2121
### 1. What language are you working in?
2222

23-
#### → I’m working in R
24-
25-
Renku only has one mode for working with R sessions at the moment. When you create a session
26-
launcher, select **global environment** and select the **R** global environment. If you need to
27-
install additional packages, see [How to install packages on-the-fly in your
28-
session](install-packages-on-the-fly-in-your-session).
29-
3023
#### → I’m working in Python
3124

3225
We have multiple ways of working in Python in Renku sessions! Please continue to the next question
3326
[2. Would you like packages to be pre-installed and ready to go when you (or anyone else) launches
3427
the
3528
session?](#2-would-you-like-packages-to-be-pre-installed-and-ready-to-go-when-you-or-anyone-else-launches-the-session).
3629

30+
#### → I’m working in R
31+
32+
If your project uses [`renv`](https://rstudio.github.io/renv/) and has an `renv.lock` file,
33+
Renku can build a code-based environment with your packages pre-installed. See [How to create an
34+
environment with custom packages
35+
installed](create-environment-with-custom-packages-installed#defining-an-r-environment-with-renv).
36+
37+
If you do not need packages pre-installed, create a session launcher with a **global environment**
38+
and select the **R** global environment. If you need to install additional packages temporarily, see
39+
[How to install packages on-the-fly in your
40+
session](install-packages-on-the-fly-in-your-session).
41+
3742
#### → I’m working in another language
3843

3944
Working in some other language? That’s ok! You can run a wide variety of Docker images in Renku
@@ -48,8 +53,8 @@ If you’d like a set of custom packages to be installed and ready to go when yo
4853
launches a session in your project, you can take advantage of Renku’s code based environments.
4954

5055
With Renku code based environments, you can point Renku to a code repository that contains an
51-
environment definition file, such as a environment.yml, requirements.txt, or pyproject.toml, and
52-
Renku will build a custom environment for your session for you!
56+
environment definition file, such as `environment.yml`, `requirements.txt`, `pyproject.toml`, or
57+
`renv.lock`, and Renku will build a custom environment for your session for you!
5358

5459
→ If your code repository is **public**, see [How to create an environment with custom packages
5560
installed](create-environment-with-custom-packages-installed).

0 commit comments

Comments
 (0)