RStudio – IDE and Server powered by Singularity

By Staff

Oct 4, 2018 | How To

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

%environment
    LC_ALL="C"
    export LC_ALL

%post
    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 https://download1.rstudio.org/rstudio-xenial-1.1.456-amd64.deb > /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 \
      https://download2.rstudio.org/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"] = "https://cran.us.r-project.org"
 options(repos = r)
})' >> /etc/R/Rprofile.site

    # 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

%runscript
    /usr/bin/rstudio "$@"

%startscript
    /usr/lib/rstudio-server/bin/rserver

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

Instance:

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

$ singularity instance start rstudio.sif rs

Run:

 This will run rstudio IDE

$ singularity run rstudio.sif

Exec:

 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:


$ SINGULARITYENV_DISPLAY=${DISPLAY} \
  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

Related Posts

Update to examples – November 9

Sylabs continues to provide example Singularity containers. Our latest installment of updates is as follows: ContikiOSContiki is an open source operating system that runs on tiny low-power microcontrollers and makes it possible to develop applications that make...

read more

Update to examples – October 2

Here are a few more Singularity containers, that we at Sylabs have put together: CaffeCaffe is a Deep Learning framework. https://github.com/sylabs/examples/tree/master/machinelearning/caffeSingularity Definition File HorovodHorovod is a distributed-training framework...

read more

Pin It on Pinterest