RStudio – IDE and Server powered by Singularity

By Staff

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
Upgrade CentOS 7 to Alma 8 While Keeping SingularityCE Updated
Overview With CentOS 7 reaching end of life on June 30th, 2024 and CentOS 8 already discontinued in favor of CentOS Stream, users of open source SingularityCE might find themselves in a situation where a migration to another open source operating system is necessary....
Introducing CDI Support to SingularityCE 4.0
With the ever increasing adoption of AI techniques in scientific research, as well as growing use of accelerators for traditional numerical workloads, easy access to GPUs and other devices in HPC environments is critical.The 4.0 release of the SingularityCE container...
Transforming Alzheimer’s Research with Singularity Containers: A Milestone in Scientific Reproducibility
Addressing The Grand Challenges of Our Time Through Singularity Container TechnologyAt Sylabs, our mission and vision aren't just statements on a wall, they're an ethos we embody daily. We're committed to facilitating cutting-edge research that seeks to address...