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.
- installed rstudio server
- installed conda
- installed uuid ("
sudo <PKG_MGR> install uuid
")
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
git clone https://github.com/grst/rstudio-server-conda.git
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.
- 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 wrappingrsession
into the rsession.sh script. The path to the wrappedrsession
executable can be passed torserver
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 torserver
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