Skip to content

Commit 29108e7

Browse files
committed
add info on the R kernel
1 parent 5fe51d9 commit 29108e7

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ py-rocket-base has pyrocket and rocket scripts that you can use to help customiz
3737
The original [py-rocket 1.0](https://github.com/NASA-Openscapes/py-rocket) was developed by Luis Lopez and was built off a Rocker base image. Carl Boettiger and Eli Holmes later altered the image (py-rocket 2.0) so that the Python environment matched the Pangeo image structure but the image was still built off a Rocker image. Subsequently, Carl Boettiger developed [repo2docker-r](https://github.com/boettiger-lab/repo2docker-r) that creates a JupyterHub-compatible image that uses a [Jupyter docker stack image](https://jupyter-docker-stacks.readthedocs.io/en/latest/) as base. For py-rocker 3.0, Eli Holmes used Carl's ideas but used [repo2docker](https://repo2docker.readthedocs.io/en/latest/) and [repo2docker-action](https://github.com/jupyterhub/repo2docker-action) to build the base image. To do this, the [CryoCloud hub image](https://github.com/CryoInTheCloud/hub-image) repo was used for the basic structure and approach. Eli added the `rocker.sh` script and `appendix` modifications to install R and RStudio via the Rocker scripts (rather than using a Rocker image as base). Yuvi Panda (repo2docker) gave input throughout the process as snags were hit.
3838

3939
**Why Rocker for the R/RStudio environment?** The Rocker images are the standard for R/RStudio contanier images. They are heavily tested and regularly updated. There is a large developer community that fixes problems and bugs. The stack has gone through major revisions to improve modularity and they constantly innovating (integration for machine-learning, CUDA, BLAS, spatial, etc., etc.). py-rocket is building off that work without using the images directly. Instead it uses the Docker file code and the installation scripts. There are many other approaches to adding R and RStudio to images that work in JupyterHubs. See [repo2docker-r](https://github.com/boettiger-lab/repo2docker-r) that Carl developed and [r-conda](https://github.com/binder-examples/r-conda) for a conda native approach using repo2docker. py-rocket is not intended to create small images; it is intended to create images that emulate Rocker in the `/rstudio` environment on a JupyterHub.
40+
41+
## Building the documentation
42+
43+
```
44+
cd book
45+
quarto render .
46+
```
47+
This puts html in `docs`. Push to GitHub.

docs/developers.html

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ <h2 id="toc-title">Table of contents</h2>
232232
<ul class="collapse">
233233
<li><a href="#terminal-in-jupyter-lab" id="toc-terminal-in-jupyter-lab" class="nav-link" data-scroll-target="#terminal-in-jupyter-lab"><span class="header-section-number">8.9.1</span> Terminal in Jupyter Lab</a></li>
234234
</ul></li>
235-
<li><a href="#notes-on-the-rstudio-environment" id="toc-notes-on-the-rstudio-environment" class="nav-link" data-scroll-target="#notes-on-the-rstudio-environment"><span class="header-section-number">8.10</span> Notes on the RStudio environment</a>
235+
<li><a href="#notes-on-r-in-the-rstudio-or-jupyter-lab-environment" id="toc-notes-on-r-in-the-rstudio-or-jupyter-lab-environment" class="nav-link" data-scroll-target="#notes-on-r-in-the-rstudio-or-jupyter-lab-environment"><span class="header-section-number">8.10</span> Notes on R in the RStudio or Jupyter Lab environment</a>
236236
<ul class="collapse">
237237
<li><a href="#environmental-variables" id="toc-environmental-variables" class="nav-link" data-scroll-target="#environmental-variables"><span class="header-section-number">8.10.1</span> Environmental variables</a></li>
238238
<li><a href="#terminal-in-rstudio" id="toc-terminal-in-rstudio" class="nav-link" data-scroll-target="#terminal-in-rstudio"><span class="header-section-number">8.10.2</span> Terminal in RStudio</a></li>
@@ -655,20 +655,28 @@ <h3 data-number="8.9.1" class="anchored" data-anchor-id="terminal-in-jupyter-lab
655655
<p>For non-login bash shells (interactive), <code>/etc/bash.bashrc</code> determines the shell environment unless the user has created <code>~/.bashrc</code>, in which case that file determines the shell environment. In Jupyter Lab, you can start and interactive shell by running <code>bash</code> (from a terminal). Be aware that if you run <code>bash</code> it might look like the conda environment is deactivated but it is really not since the <code>PATH</code> still includes <code>conda</code> in it. If you are trying to get remove <code>conda</code> from the path (and get rid of all the conda environment variables) you need to run <code>conda deactivate</code> (2x).</p>
656656
</section>
657657
</section>
658-
<section id="notes-on-the-rstudio-environment" class="level2" data-number="8.10">
659-
<h2 data-number="8.10" class="anchored" data-anchor-id="notes-on-the-rstudio-environment"><span class="header-section-number">8.10</span> Notes on the RStudio environment</h2>
660-
<p><a href="https://github.com/jupyterhub/jupyter-rsession-proxy">jupyter-rsession-proxy</a> allows us to launch RStudio from Jupyter Lab, but the environment is different than the environment in Jupyter Lab.</p>
658+
<section id="notes-on-r-in-the-rstudio-or-jupyter-lab-environment" class="level2" data-number="8.10">
659+
<h2 data-number="8.10" class="anchored" data-anchor-id="notes-on-r-in-the-rstudio-or-jupyter-lab-environment"><span class="header-section-number">8.10</span> Notes on R in the RStudio or Jupyter Lab environment</h2>
660+
<p><a href="https://github.com/jupyterhub/jupyter-rsession-proxy">jupyter-rsession-proxy</a> in <code>environment.yml</code> allows us to launch RStudio from Jupyter Lab and <code>IRkernel</code> run in our R installation via this in the Docker file</p>
661+
<pre><code>RUN Rscript -e "install.packages('IRkernel')" &amp;&amp; \
662+
PATH=/srv/conda/envs/notebook/bin:$PATH Rscript -e "IRkernel::installspec(name = 'ir', displayname = 'R ${R_VERSION}')"</code></pre>
663+
<p>creates a Jupyter Lab kernel called <code>R X.X.X</code> using our R installation (in <code>/usr/local/bin/R</code>) with all our libraries.</p>
664+
<p>However we enter the R environment (either in Jupyter Lab or RStudio), the environment is different than the default environment if you use the default Python environment (the conda ‘notebook’ environment).</p>
661665
<section id="environmental-variables" class="level3" data-number="8.10.1">
662666
<h3 data-number="8.10.1" class="anchored" data-anchor-id="environmental-variables"><span class="header-section-number">8.10.1</span> Environmental variables</h3>
663667
<ul>
664-
<li>PATH is different. conda is not on the path.</li>
665-
<li>None of the environmental variables in the docker file will be in the <code>/rstudio</code> environment. The start command affects <code>\lab</code> and <code>\notebook</code> but not <code>\rstudio</code>.</li>
668+
<li>PATH is different. conda is not on the path. Try <code>Sys.getenv("PATH")</code>. This is on purpose because the R geospatial packages get confused if one uses the GDAL associated with the conda environment. This is critical to know if you are using <code>reticulate</code> and <code>Python</code> inside of R. conda will not be on the path and all the Python libraries will not be accessible. If you want to use the conda environment, you have to run this. The first line tells R where the conda binary is because it has no way to find it since conda is not on its system PATH.</li>
666669
</ul>
667-
<p>If you need some environmental variable set, you will need to set those in <code>$R_HOME/etc/Rprofile.site</code> which is run when R starts.</p>
670+
<pre><code>options(reticulate.conda_binary = "/srv/conda/condabin/conda")
671+
reticulate::use_condaenv("/srv/conda/envs/notebook", required = TRUE)</code></pre>
672+
<ul>
673+
<li><strong>For RStudio only</strong>: None of the environmental variables in the docker file will be in the <code>/rstudio</code> environment. The start command affects <code>\lab</code> and <code>\notebook</code> but not <code>\rstudio</code>. I have made some attempt to add back in a few required ones in <code>/usr/local/lib/R/etc/Rprofile.site</code> but it is very minimal.</li>
674+
</ul>
675+
<p>If your users need some environmental variable set, they will need to set those in <code>$R_HOME/etc/Rprofile.site</code> which is run when R starts.</p>
668676
</section>
669677
<section id="terminal-in-rstudio" class="level3" data-number="8.10.2">
670678
<h3 data-number="8.10.2" class="anchored" data-anchor-id="terminal-in-rstudio"><span class="header-section-number">8.10.2</span> Terminal in RStudio</h3>
671-
<p>The default way that a terminal is started is <code>bash -l</code> which means it is a login terminal. When a login terminal launches, <code>/etc/profile</code> script is run. For this image, this script will execute all the scripts in the directory <code>/etc/profile.d</code>. You can add scripts there that you want to run when a login terminal is started. In particular, there is the script <code>init_conda.sh</code>. This ensures that when a terminal is opened from the Launcher in JupyterLab, the conda notebook environment is activated. However, we do not want this to happen in RStudio so the script checks if RSTUDIO==1 and R_HOME is set, if that is true then we are in the RStudio UI and conda should not be initialized.</p>
679+
<p>The default way that a terminal is started is <code>bash -l</code> which means it is a login terminal. When a login terminal launches, <code>/etc/profile</code> script is run. For this image, this script will execute all the scripts in the directory <code>/etc/profile.d</code>. You can add scripts there that you want to run when a login terminal is started. In particular, there is the script <code>init_conda.sh</code>. This ensures that when a terminal is opened from the Launcher in JupyterLab, the conda notebook environment is activated. However, we do not want this to happen in RStudio so the script checks if RSTUDIO==1 and R_HOME is set, if that is true then we are in the RStudio UI and conda should not be initialized (and is not).</p>
672680

673681

674682
</section>

docs/search.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,11 @@
390390
]
391391
},
392392
{
393-
"objectID": "developers.html#notes-on-the-rstudio-environment",
394-
"href": "developers.html#notes-on-the-rstudio-environment",
393+
"objectID": "developers.html#notes-on-r-in-the-rstudio-or-jupyter-lab-environment",
394+
"href": "developers.html#notes-on-r-in-the-rstudio-or-jupyter-lab-environment",
395395
"title": "8  Developer notes",
396-
"section": "8.10 Notes on the RStudio environment",
397-
"text": "8.10 Notes on the RStudio environment\njupyter-rsession-proxy allows us to launch RStudio from Jupyter Lab, but the environment is different than the environment in Jupyter Lab.\n\n8.10.1 Environmental variables\n\nPATH is different. conda is not on the path.\nNone of the environmental variables in the docker file will be in the /rstudio environment. The start command affects \\lab and \\notebook but not \\rstudio.\n\nIf you need some environmental variable set, you will need to set those in $R_HOME/etc/Rprofile.site which is run when R starts.\n\n\n8.10.2 Terminal in RStudio\nThe default way that a terminal is started is bash -l which means it is a login terminal. When a login terminal launches, /etc/profile script is run. For this image, this script will execute all the scripts in the directory /etc/profile.d. You can add scripts there that you want to run when a login terminal is started. In particular, there is the script init_conda.sh. This ensures that when a terminal is opened from the Launcher in JupyterLab, the conda notebook environment is activated. However, we do not want this to happen in RStudio so the script checks if RSTUDIO==1 and R_HOME is set, if that is true then we are in the RStudio UI and conda should not be initialized.",
396+
"section": "8.10 Notes on R in the RStudio or Jupyter Lab environment",
397+
"text": "8.10 Notes on R in the RStudio or Jupyter Lab environment\njupyter-rsession-proxy in environment.yml allows us to launch RStudio from Jupyter Lab and IRkernel run in our R installation via this in the Docker file\nRUN Rscript -e \"install.packages('IRkernel')\" && \\\n PATH=/srv/conda/envs/notebook/bin:$PATH Rscript -e \"IRkernel::installspec(name = 'ir', displayname = 'R ${R_VERSION}')\"\ncreates a Jupyter Lab kernel called R X.X.X using our R installation (in /usr/local/bin/R) with all our libraries.\nHowever we enter the R environment (either in Jupyter Lab or RStudio), the environment is different than the default environment if you use the default Python environment (the conda ‘notebook’ environment).\n\n8.10.1 Environmental variables\n\nPATH is different. conda is not on the path. Try Sys.getenv(\"PATH\"). This is on purpose because the R geospatial packages get confused if one uses the GDAL associated with the conda environment. This is critical to know if you are using reticulate and Python inside of R. conda will not be on the path and all the Python libraries will not be accessible. If you want to use the conda environment, you have to run this. The first line tells R where the conda binary is because it has no way to find it since conda is not on its system PATH.\n\noptions(reticulate.conda_binary = \"/srv/conda/condabin/conda\")\nreticulate::use_condaenv(\"/srv/conda/envs/notebook\", required = TRUE)\n\nFor RStudio only: None of the environmental variables in the docker file will be in the /rstudio environment. The start command affects \\lab and \\notebook but not \\rstudio. I have made some attempt to add back in a few required ones in /usr/local/lib/R/etc/Rprofile.site but it is very minimal.\n\nIf your users need some environmental variable set, they will need to set those in $R_HOME/etc/Rprofile.site which is run when R starts.\n\n\n8.10.2 Terminal in RStudio\nThe default way that a terminal is started is bash -l which means it is a login terminal. When a login terminal launches, /etc/profile script is run. For this image, this script will execute all the scripts in the directory /etc/profile.d. You can add scripts there that you want to run when a login terminal is started. In particular, there is the script init_conda.sh. This ensures that when a terminal is opened from the Launcher in JupyterLab, the conda notebook environment is activated. However, we do not want this to happen in RStudio so the script checks if RSTUDIO==1 and R_HOME is set, if that is true then we are in the RStudio UI and conda should not be initialized (and is not).",
398398
"crumbs": [
399399
"<span class='chapter-number'>8</span>  <span class='chapter-title'>Developer notes</span>"
400400
]

docs/sitemap.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</url>
3535
<url>
3636
<loc>https://nmfs-opensci.github.io/py-rocket-base/developers.html</loc>
37-
<lastmod>2025-03-04T18:45:41.534Z</lastmod>
37+
<lastmod>2025-04-12T22:19:10.568Z</lastmod>
3838
</url>
3939
<url>
4040
<loc>https://nmfs-opensci.github.io/py-rocket-base/related.html</loc>

0 commit comments

Comments
 (0)