Repo cloned from https://github.com/grst/rstudio-server-conda and adjusted for easier use with singularity
I usually rely on the conda package manager to manage my environments during development. Thanks to conda-forge and bioconda most R packages are now also available through conda. For production, I convert them to containers as these are easier to share.
Unfortunately, there seems to be no straightforward way to use conda envs in Rstudio server. This repository provides three approaches to make rstudio server work with conda envs.
- Running Rstudio Server in a Singularity Container
- Running Rstudio Server in a Docker/Podman Container
- Running Rstudio Server locally
With this approach Rstudio Server runs in a Singularity container (any based on rocker/rstudio).
The conda environment gets mounted into the container - like that there's no need to rebuild the container to add a package and
install.packages
can be used without issues. The container-based approach has the following benefits:
- Authentication works (#3)
- Several separate instances of Rstudio server can run in parallel, even without the Pro version.
- R version can easily be switched by mounting different conda environment.
-
Clone this repository
-
Activate the target conda env or set the environment variable
CONDA_PREFIX
to point to the location of the conda env. -
Check the '/singularity/init.sh' script. You need to adjust the path to miniconda.
-
Check the
run_singularity.sh
script. In particular, you may need to add additional bind mounts (e.g. a global data directory), add path to your favorite container, add path to your favority conda prefix. -
Execute the
run_singularity.sh
script. It will automatically build the container if it is not available.PORT=8585 PASSWORD=rstudio CONDA_PREFIX="./my_Tools/myPY/envs/r43_env" CONTAINER="./tidyverse_latest.sif" ./singularity/run_singularity.sh
-
Open a tunnel to the compute server running the container
ssh -N -L 8585:{node}:8585 {user}@hpc-login
-
Log into Rstudio
- open rstudio server at
http://localhost:8585
(or whatever port you specified) - login with your default username and the password you specified via the
PASSWORD
environment variable. - Sometimes, running multiple sessions from the same IP adress using the same browser can result in different sessions using the same secure-cookie-key. This causes sessions to disconnect and converge into 1 session. A work-around is using Firefox container tabs; https://support.mozilla.org/en-US/kb/how-use-firefox-containers. Follow the description in the link and assign each session to its own container. Now you should be able to run multiple rstudio sessions simultaneously without sessions interfering with each other.
- open rstudio server at