Run RStudio Interactively

On Nimbus, you can run RStudio interactively. It requires four main steps:

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 to run RStudio interactively.

1. Open port 8787 on Nimbus dashboard


From the Nimbus dashboard:

1.

Navigate to NetworkSecurity 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.

Use the container method only if you know the libraries that you require to install the packages you need.

3. Open RStudio from a browser


  1. Open up a browser window 
  2. Go to your instance IP address with the 8787 port, e.g. 146.118.XX.XX:8787
  3. Enter the username you created, e.g. rstudio (or if using a container, ubuntu)
  4. Enter the password you gave it.
  5. Run your R commands as you normally would

    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.

    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.

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).

To do so, run the following command:

$ echo "R_LIBS_USER=/home/rstudio/R/x86_64-pc-linux-gnu-library/4.1" > ~/.Renviron

You can check that your library paths are indeed correct from your instance:

$ 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: 

$ cat ~/.Renviron
R_LIBS_USER=/home/rstudio/R/x86_64-pc-linux-gnu-library/4.2:/home/rstudio/R/x86_64-pc-linux-gnu-library/4.1

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:

$ 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"