Skip to content

Run Rstudio Server in an a anaconda environment

License

Notifications You must be signed in to change notification settings

jtelleriar/rstudio-server-conda

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Howto run Rstudio Server in an Anaconda 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

About

Run Rstudio Server in an a anaconda environment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 53.7%
  • R 46.3%