All Projects → grst → Rstudio Server Conda

grst / Rstudio Server Conda

Licence: mit
Run Rstudio Server in a conda environment

Programming Languages

shell
77523 projects

Howto run Rstudio Server in a Conda Environment

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.

Unfortunately, there seems to be no straightforward way to use conda envs in Rstudio server. This is why I came up with the two scripts in this repo.

Installation and usage

1. Prerequisites

2. Disable rstudio server service.

You might need to disable the system-wide Rstudio server service. Due to licensing restrictions of rstudio server community edition, only one rstudio process can run for each user simultaneously.

This is how it works on systemd-based systems:

sudo systemctl disable rstudio-server.service
sudo systemctl stop rstudio-server.service

3. Clone this repo

git clone https://github.com/grst/rstudio-server-conda.git

4. Run rstudio server in the conda env

conda activate my_project
./start_rstudio_server.sh 8787  # use any free port number here. 

You should now be able to connect to rstudio server on the port you specify. If an R Session has previously been running, you'll need to rstart the Rsession now.

Obviously, if your env does not have a version of R installed, this will either not work at all, or fall back to the system-wide R installation.

How it works

  • Rstudio server, can be started in non-daemonized mode by each user individually on a custom port (similar to a jupyter notebook). This instance can then run in a conda environment:
> conda activate my_project
> /usr/lib/rstudio-server/bin/rserver \
   --server-daemonize=0 \
   --www-port 8787 \
   --rsession-which-r=$(which R) \
   --rsession-ld-library-path=$CONDA_PREFIX/lib
  • To avoid additional problems with library paths, also rsession needs to run within the conda environment. This is achieved by wrapping rsession into the rsession.sh script. The path to the wrapped rsession executable can be passed to rserver as command line argument.
rserver # ...
    --rsession-path=rsession.sh
  • When using multiple users a unique secret-cookie-key has to be generated for each user. The path to the secret cookie key can be passed to rserver as a command line parameter.
uuid > /tmp/rstudio-server/${USER}_secure-cookie-key
rserver # ...
  --secure-cookie-key-file /tmp/rstudio-server/${USER}_secure-cookie-key
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].