skip to Main Content
RStudio – IDE And Server Powered By Singularity

RStudio – IDE and Server powered by Singularity

RStudio is an Integrated Development Environment (IDE) for the R language. By containerizing RStudio, a scientist can leverage the reproducibility and portability of the Singularity platform, allowing them to build data visualizations and analysis tools and ensure that they behave exactly the same in a new environment.   

The Singularity definition (def) file is:

Bootstrap: library
From: debian:9

    export LC_ALL

    apt-get update
    apt-get -y install systemd systemd-sysv gdebi-core procps libssl1.1 ed wget curl libqt5webkit5 libqt5core5a
    apt-get -y install r-base r-base-dev

    curl > /rstudio-1.1.456-amd64.deb
    apt-get -y install /rstudio-1.1.456-amd64.deb

    wget -O /rstudio-server-stretch-1.1.456-amd64.deb \
    gdebi -n /rstudio-server-stretch-1.1.456-amd64.deb

    # Setup the "general" CRAN repo
    echo 'local({
 r <- getOption("repos")
 r["CRAN"] = ""
 options(repos = r)
})' >> /etc/R/

    # We are setting up a normal user for access
    # Login: rstudio  Password: rstudio
    useradd -c "RStudio Account" -u 500 -d /home/rstudio -s /bin/bash rstudio
    echo "rstudio:rstudio" | /usr/sbin/chpasswd

    # Move systemd service file into place
    cp /usr/lib/rstudio-server/extras/systemd/rstudio-server.service /lib/systemd/system/
    systemctl enable rstudio-server

    # Remove unneeded source packages
    rm -f /rstudio-1.1.456-amd64.deb
    rm -f /rstudio-server-stretch-1.1.456-amd64.deb

    /usr/bin/rstudio "$@"


The definiton file affords some flexibility, allowing you to run RStudio several different ways:

 This will start up rstudio-server, on default port of 8787

$ singularity instance start rstudio.sif rs

 This will run rstudio IDE

$ singularity run rstudio.sif

 Any program in the container, but specifically for running R directly.

$ singularity exec rstudio.sif R -f myfile.r

To build the image run:

$ sudo singularity build rstudio.sif rstudio.def

When you use run for the IDE, you may need to execute it like:

  singularity run rstudio.sif

This is needed only if the DISPLAY environment variable does not automatically propagate from your host environment to the container.

For a modification of rstudio-server, you can create a rstudio.conf file, and bind mount it into the container. For example to run on port 9999:

$ echo "www-port=9999" > rserver.conf
$ singularity instance start \
  -B rserver.conf:/etc/rstudio/rserver.conf \
  rstudio.sif rs

You will then access your rstudio-server instance at:  https://localhost:9999

Back To Top