On Nimbus, you can run RStudio interactively. It requires four main steps:
Table of Contents
This is an example of what can be achieved on Nimbus Research Cloud. The detailed configuration for various VM flavours and OS configurations might differ. Nimbus users are responsible for managing their VMs and installing tools. We believe that this step-by-step example might be helpful torun RStudio interactively.
1. Open port 8787 on Nimbus dashboard
From the Nimbus dashboard:
1.
Navigate to Network > Security Groups:
2.
Click on + Create Security Group, name it 'port 8787' and then select the Create Security Group button:
3.
Select + Add Rule:
4.
Then enter the port number 8787 under 'Port', and click on the Add button:
5.
Navigate back to Compute > Instances, then click on the arrow down button for the your instance, and select Edit Security Groups. Ensure that you select the port 8787 security group that you have just created, i.e. it should appear on the right hand side list of Instance Security Groups:
2. Run RStudio
You may choose to run RStudio from your instance, or from a container on your instance.
Note
Use the container method only if you know the libraries that you require to install the packages you need.
Ui tabs
Ui tab
title
From your instance
2.1. From your instance
On your Nimbus instance:
2.1.1. Create a user
You will need to create a user on your instance as the RStudio Server does not permit system users (i.e. ubuntu or root).
It is important to set a secure password as your RStudio server can be accessible to anyone on the internet, potentially compromising your instance as a result.
You can give it a username of your choice. The example here is rstudio.
If there is no prompt to add a password:
Change the ownership of the /home/rstudio directory and its contents so that you can also access it as ubuntu:
Change the write permissions on the /home/rstudio directory and its subdirectories so that RStudio can write into them:
2.1.2. Install R & RStudio Server
If your instance is created from the Nimbus image 'Pawsey Bio - March 2023 - Ubuntu 22.04', R and RStudio Server have already been installed, so you can proceed to the next step: 2.1.3. Start Rstudio Server
Ubuntu
CentOS
Ubuntu
CentOS
2.1.3. Start Rstudio Server
To check the RStudio server status:
If required, start the RStudio Server:
Ui tab
title
From a container
2.2. From a container on your instance
On your Nimbus instance:
The following command assumes that you have Singularity installed. All Pawsey have Singularity pre-installed. If you need to install Singularity, see the documentation .
2.2.1. Build RStudio container (R=4.1.0)
*** Currently supporting only R version 4.1.0***
As an example, to create an image with an RStudio base, first create a new directory in your /data or /scratch folder to store all relevant RStudio files. The /data or /scratch folder should be the volume you created as per .
Create a Dockerfile:
Libraries and packages
Note: We have found the following list of libraries and java packages to be useful in particular to bioinformatics R packages. You can choose to copy the Dockerfile as above or add/remove lines as you require.
Add R packages
At this stage, if you require any known R package(s), add each package as a new line, appending with a '\' if it is not the final line, accordingly in the Dockerfile.
If you require a certain version of a package, you will have to add a new line for it after the first RUN section, specifying the url path, e.g.
RUN R -e 'install.packages("https://cran.rstudio.com/src/contrib/matrixStats_0.63.0.tar.gz", repos = NULL, type = "source")'
If adding more than one package, make sure to pass it as a vector, e.g.
RUN R -e 'install.packages(c("https://cran.r-project.org/src/contrib/magick_2.7.3.tar.gz", "https://cran.rstudio.com/src/contrib/matrixStats_0.63.0.tar.gz"), repos = NULL, type = "source")'
Add Bioconductor packagesIf any Bioconductor packages are required, append the 'BiocManager::install()' function with the packages you require. As an example, DESeq2 and GenomicFeatures have been added to the function below.
Dockerfile-rstudio
Build the Docker image:
This step will take about 10-15 minutes as your image is being created with the above packages compiled within.
Disk space
If you get an error about being out of disk or device space, it is usually due to your root disk having filled up and Docker not having enough space to create intermediate files when building the image. We advise that you move all data files and files not needed on the root volume to your mounted data or scratch volume. Check that your root volume has at least 10-20GB of available space by running df -h. The root volume is usually 40GB. You may also want to check that you have removed all unused and dangling Docker images and containers by running a system prune, i.e. docker system prune. Then run the build or pull command(s) again.
Make a new directory in your attached volume e.g. /data folder, then export it as a Singularity cache directory. This step is so that Singularity does not store its cache in your (/home/ubuntu) root disk, which can get filled quickly. The final command also ensures that every time you log in to your instance, the cache directory remains exported to that path. (Replace /data with the appropriate mount point for your attached volume as necessary):
Pull and convert the Docker image into a Singularity container:
Your Singularity container will be titled rstudio-4.1.0.sif and located in the current working directory, which should still be /data/rstudio.
2.2.2. Execute the container to start the Rstudio Server
First, create a rstudio-server folder on your instance:
Set a password for your RStudio server:
It is important to set a secure password as your RStudio server can be accessible to anyone on the internet, potentially compromising your instance as a result. In this example, the password is being randomly generated with the openssl command. Make sure you save this password so that you can login to the same server again later.
If you want to run the container in the background, you can create a screen session:
Then, execute the container as follows:
singularity exec invokes the container to run the rserver command.
-B is a flag used to for bind-mounting /data, which is a directory on your instance. /home is the container's directory /data is bind-mounted to. Do not replace /home.
You can replace /data with a directory of your choice, as long as it has user ownership.
All output from your R session is saved to the /data/rstudio directory (or another parent directory you may have bind-mount in the RStudio server command).
You should not see any output at this point, except a "running" command, i.e. the RStudio server running.
(If you executed the container from a screen session, you can detach the session with ctrl+a+d. To reattach, run screen -r my-rstudio-session.)
3. Open RStudio from a browser
Open up a browser window
Go to your instance IP address with the 8787 port, e.g. 146.118.XX.XX:8787
Enter the username you created, e.g. rstudio (or if using a container, ubuntu)
Enter the password you gave it.
Run your R commands as you normally would
Warning
title
Working directory
If you are using RStudio from your instance, make sure to change your working directory to your mounted data volume, e.g. /data. If you ran RStudio from a container, do not change the working directory, as the container's /home/rstudio is bind mount to the /data folder on your instance.
Code Block
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> getwd()
[1] "/home/rstudio"
> setwd("/data")
> getwd()
[1] "/data"
4. End your RStudio session and server
To end the interactive session, simply exit from the browser. Your session will still be live, unless you also stop the server on your Nimbus instance.
Ui tabs
Ui tab
title
From your instance
If your ran RStudio from your instance, stop and check that the server has stopped. The output should read as "inactive" as follows:
Ui tab
title
From a container
If you ran RStudio from a container, stop the running command with ctrl+c:
Or kill the process on the port:
5. Important notes
If you have installed packages from the interactive session in RStudio, and would like to also run R directly from the instance on command line, please note that the R library path needs to be prepended with the RStudio library path. This is because the default R library path (user=ubuntu) is different to the RStudio library path (user=rstudio).
You can check that your library paths are indeed correct from your instance:
Code Block
$ R
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Previously saved workspace restored]
> .libPaths()
[1] "/home/rstudio/R/x86_64-pc-linux-gnu-library/4.1"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"
If you are using or have installed a different R version, you will need to change or add to it accordingly. The above library path is for R version 4.1.X. For example, if you have R version 4.2.1, your ~/.Renviron file would need to be edited to look like this:
This ensures that all new packages are installed to the 4.2 library instead of the 4.1 library. But packages will still be accessible in the 4.1 library for read and write.
To check, from your instance:
Code Block
$ R
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Previously saved workspace restored]
> .libPaths()
[1] "/home/rstudio/R/x86_64-pc-linux-gnu-library/4.2"
[2] "/home/rstudio/R/x86_64-pc-linux-gnu-library/4.1"
[3] "/usr/local/lib/R/site-library"
[4] "/usr/lib/R/site-library"
[5] "/usr/lib/R/library"