Link Conda to RStudio
Accessing RStudio on Rockfish Using R from a Conda Environment
This tutorial guides you through launching RStudio Server on Rockfish using R installed inside a Conda environment.
Connect to Rockfish (Login Node)
Open a terminal and run:
ssh YourUserID@login.rockfish.jhu.edu
Enter your Rockfish password when prompted.
Create a Module for Your Conda Environment
Load Anaconda:
module load anaconda3/2024.02-1
Activate your Conda environment:
conda activate my_conda_env
Generate a modulefile for your environment:
conda_to_lua.sh
This will create a module named after your Conda environment (e.g.,
my_conda_env) in your user module path.Deactivate the Conda environment:
conda deactivate
Create a SLURM Script with r-studio-server.sh
r-studio-server.sh -c 10 -t 02:00:00 -p shared
Argument Explanation:
-c: Number of cores (each core provides ~4 GB RAM)-t: Runtime inHH:MM:SS-p: Partition -express: up to 4 cores / 8 hours -shared: up to 32 cores / 36 hours -parallel: up to 48 cores / 72 hours
You can run r-studio-server.sh --help to view all available options.
Edit the Generated SLURM Script
nano R-Studio-Server.slurm.script
Inside the file:
Locate the line:
module restoreDirectly below it, add a line to load your Conda module:
module load own my_conda_env
Find the line:
export R_LIBS_USER=${HOME}/R/4.2.1
Replace it with the path to your Conda environment’s R library:
export R_LIBS_USER=/home/YOUR_USERNAME/.conda/envs/my_conda_env/lib/R/library
Replace YOUR_USERNAME with your Rockfish username and my_conda_env with your Conda environment name.
Save and exit:
Ctrl + O, then Enter to saveCtrl + Xto exit
Update RStudio Configuration
nano .r-studio-variables
Replace the following lines:
Line 13:
module load gfbf/2023b RStudio-Server/2023.12.1+402-gfbf-2023b-Java-11-R-4.4.1
Line 14:
ml -R/4.4.1-gfbf-2023b
Save and exit:
Ctrl + O, then Enter to saveCtrl + Xto exit
Submit the Job
sbatch R-Studio-Server.slurm.script
This will generate a file named:
rstudio-server.job.<jobid>.out
Locate the Output File
ls -ltr rstudio-server.job*
View Connection Instructions
cat rstudio-server.job.<jobid>.out
Inside the file, you’ll find two important things:
The SSH tunnel command
The localhost URL to open in your browser
Set Up the SSH Tunnel (Local Machine)
On your local terminal (not logged into Rockfish), run:
ssh -N -L <PORT>:<node>:<PORT> YourUserID@login.rockfish.jhu.edu
Replace values accordingly. You’ll be prompted for your password — enter it and leave this terminal open.
Access RStudio
From the .out file, copy the URL starting with:
http://localhost:<PORT>/...
Paste it into your web browser and log in with your Rockfish credentials.