• Stars
    star
    151
  • Rank 245,308 (Top 5 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run Rstudio Server in a conda environment

Running 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. 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 with Singularity

With this approach Rstudio Server runs in a Singularity container (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.

Prerequisites

Usage

  1. Clone this repository

    git clone [email protected]:grst/rstudio-server-conda.git
    cd rstudio-server-conda/singularity
  2. Activate the target conda env or set the environment variable CONDA_PREFIX to point to the location of the conda env.

  3. Check the run_singularity.sh script. In particular, you may need to add additional bind mounts (e.g. a global data directory).

  4. Execute the run_singularity.sh script. It will automatically build the container if it is not available.

    PORT=8787 PASSWORD=notsafe ./run_singularity.sh
  5. Log into Rstudio

    • open rstudio server at http://localhost:8787 (or whatever port you specified)
    • login with your default username and the password you specified via the PASSWORD environment variable.

Running Rstudio Server with Podman/Docker

This approach is similar to Singularity, but uses Docker or Podman and a docker-compose.yml file instead.

Known limitations

  • No access to shared group directories (#14)

Prerequisites

Usage

  1. Clone this repository

    git clone [email protected]:grst/rstudio-server-conda.git
  2. Build the rstudio container (fetches the latest version of rocker/rstudio and adds some custom scripts)

    cd rstudio-server-conda/docker
    docker-compose build     # or podman-compose
  3. Copy the docker-compose.yml file into your project directory and adjust the paths.

    You may want to add additional volumes with your data.

    [...]
       ports:
          # port on the host : port in the container (the latter is always 8787)
          - "8889:8787"
        volumes:
          # mount conda env into exactely the same path as on the host system - some paths are hardcoded in the env.
          - /home/sturm/anaconda3/envs/R400:/home/sturm/anaconda3/envs/R400
          # Share settings between rstudio instances
          - /home/sturm/.local/share/rstudio/monitored/user-settings:/root/.local/share/rstudio/monitored/user-settings
          # mount the working directory containing your R project.
          - /home/sturm/projects:/projects
        environment:
          # password used for authentication
          - PASSWORD=notsafe
          # repeat the path of the conda environment (must be identical to the path in "volumes")
          - CONDAENV=/home/sturm/anaconda3/envs/R400
  4. Run your project-specific instance of Rstudio-server

    docker-compose up 
  5. Log into Rstudio

  • Open your server at http://localhost:8889 (or whatever port you specified)
  • Login with the user rstudio (when using Docker) or root (when using Podman) and the password you specified in the docker-compose.yml. If you are using Podman and login with rstudio you won't have permissions to access the mounted volumes.

Running Locally

With this approach a locally installed Rstudio server is ran such that it uses the conda env.

Known limitations

  • no authentication (#3). Use this approach only in a secure network!

Prerequisites

Usage

  1. Clone this repo

    git clone https://github.com/grst/rstudio-server-conda.git
    
  2. Run rstudio server in the conda env

    cd rstudio-server-conda/local
    conda activate my_project
    ./start_rstudio_server.sh 8787  # use any free port number here. 
    
  3. Connect to Rstudio

    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
    

More Repositories

1

containerize-conda

Turn an existing conda environment into a Singularity container
Python
63
star
2

nbimporter

Import ipython notebooks as modules
Python
58
star
3

geos

Google Earth Overlay Server - display map overlays in Google Earth
Python
42
star
4

snakemake_nextflow_wdl

simple comparison of snakemake, nextflow and cromwell/wdl
wdl
36
star
5

nxfvars

Access nextflow variables from python scripts or notebooks
Python
19
star
6

python-ci-versioneer

Use github actions to autobump python versions (versioneer alternative)
Python
17
star
7

mapsources

Custom map sources for GEOS (MOBAC compatible)
Jupyter Notebook
11
star
8

jukitty

Proof of concept for a console-based jupyter lab.
Python
10
star
9

reportsrender

Render HTML reports from parametrized jupyter notebooks or Rmarkdown documents.
HTML
10
star
10

energymeter

Using a raspberry pi to monitor energy consumption in the house
Python
8
star
11

dask-on-slurm

Tutorial on how to run dask on a SLURM cluster.
Jupyter Notebook
4
star
12

universal_analysis_pipeline

Nextflow-based pipeline to run and deploy reproducible analyses.
Nextflow
3
star
13

bd_rhapsody_velocyto

Nextflow workflow to run velocyto.py on BD Rhapsody BAM files
Nextflow
3
star
14

single-cell-preprocessing-figure

An overview of different single-cell processing paths (from counts to UMAP)
2
star
15

nf-core-test-modules

Nextflow pipeline to run all tests from the nf-core-modules repository"
Nextflow
2
star
16

scanpy_reproducibility

Demonstrate that UMAP and Leiden analysis is not reproducible between different cpu architectures.
Python
2
star
17

scanpy_helpers

My custom helper functions for scanpy-based single-cell analyses.
Python
2
star
18

single-cell-analysis-nf

(Semi-)automatization of scRNA-seq QC, filtering and normalization down to an initial clustering based on scanpy and nextflow. Attempts to implement Malte LΓΌcken's best practices: https://www.embopress.org/doi/full/10.15252/msb.20199416
Jupyter Notebook
2
star
19

pygenesig

a framework to generate and validate tissue-specific gene signatures.
Python
2
star
20

microbio

Minimalist python framework for dealing with biological data
Python
2
star
21

single_cell_data_integration

Python
1
star
22

rostlab-tbg

The Bioinformatics Game for Android and iOS
C++
1
star
23

li_et_al_cell_2018_melanoma_scrna

Forked from https://bitbucket.org/tanaylab/li_et_al_cell_2018_melanoma_scrna
R
1
star
24

apache-spark-presentation

short demonstration on how to use apache spark for data analysis.
Jupyter Notebook
1
star
25

nextflow-notebook-pipeline

Example how to use nf-core/jupyternotebook and nf-core/rmarkdownnotebook modules
Nextflow
1
star
26

BioQC-GTEx-signatures

R
1
star
27

bioqc_geo

Supplementary material for "Tissue heterogeneity is prevalent in gene expression studies"
Jupyter Notebook
1
star
28

quantiseq_in_r

run the quanTIseq deconvolution step on a gene expression matrix directly in R
R
1
star
29

fantom5-sig

Extracting cell specific gene signatures from FANTOM5
Jupyter Notebook
1
star
30

minimal-nextflow-template

Template repo for minimal nextflow pipelines. Use this instead of manually submitting SGE jobs.
Nextflow
1
star