Maintaining Open Source Singularity Since 2017
RStudio – IDE and Server powered by Singularity
By Adam Hughes
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
Join Our Mailing List
Recent Posts
Related Posts
Laying the Groundwork for 2025: Sylabs’ Vision for Secure Multi-Cloud Solutions
With a legacy rooted in innovation through the work we’ve done with the Singularity platform, Sylabs has consistently worked to provide secure container technology to empower researchers, enterprises, and innovators worldwide. These efforts have paid dividends as we...
Creating New Levels of Security with Containers and Confidential Computing
Data breaches are becoming increasingly common. It's more important than ever to find robust solutions that protect sensitive information. Recent high-profile data breaches underscore the necessity for fresh approaches to data protection. Breaches like these are...
OCI-SIF Container Images: Unraveling Their Features and Benefits
Among the container industry, OCI (Open Container Initiative) and SIF (Singularity Image Format) stand out as two prominent formats, each offering unique features and benefits. Understanding their distinct characteristics is crucial for HPC developers seeking optimal...