---
# System prepended metadata

title: Connecting to Rstudio Server on Farm
tags: [R, farm]

---

---
title: Connecting to Rstudio Server on Farm
tags: R, Rstudio, guide, farm
---
# Connecting to Rstudio Server on Farm

[Link](https://github.com/dib-lab/farm-notes/issues/44) to Titus's Github Instructions


### Starting a Tmux session
I highly recommend starting a tmux session to run R (can also use screen ):
```
tmux new -s rstudio
```

To detach from your tmux session use **Ctrl+B** then **D**


To relogin or reattach to the session
```
tmux a -t rstudio
```

### Connecting to Rstudio on Farm using without a Conda Environment

Rstudio can not run on the head node, must start a srun (example below)
```
srun -p bmm --time=12:00:00 --nodes=1 \
    --cpus-per-task 2 --mem 100GB --pty /bin/bash
```

If you have conda installed, you may need to run the following to use the system provided R module:
```
conda deactivate
unset CONDA_EXE
```

To use a system-installed R package:
```
module load R
```

Load and run rstudio server
```
module load rstudio-server
rstudio-launch
```

You should then see a message like this:
```
Run the following command in a new terminal on your computer:

    ssh -L52842:aa10:52842 username@farm.hpc.ucdavis.edu
```
- Copy the newly generated ssh and paste it in a new terminal on your computer. **Do not close your current terminal.**


You should also see this message:
```
Then, on your computer, navigate your browser to:

    URL: http://localhost:12345
    Username: username
    Password: very-long-pass-word-copy-and-past-in-brower
```
- Copy and paste the url into your web browser of choice. When prompted for username and password, use the provided username and password.

You should then be able to use Rstudio on Farm.

### Connecting to Rstudio on Farm using a Conda Environment


Recommend starting a tmux session to run R (can also use screen ):
```
tmux new -s rstudio
```

To relogin to the session
```
tmux a -t rstudio
```

Create a conda environemetn
```
conda create -n r-env
```
Activate the conda env:
```
conda activate r-env
```

Make sure your channels are in the correct order:
```
conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge
conda config --set channel_priority strict
```
- if this doesn't work may need to check [Bioconda](https://bioconda.github.io/#usage)to see if the recommended configuration has changed
To created a new R environment with phyloseq use:
```
mamba create -n r-env2 bioconductor-phyloseq
```

Or you can name the conda environment, r-env if it is your first R environment
```
mamba create -n r-env bioconductor-phyloseq
```

Rstudio can not run on the head node, must start a srun (example below)
```
srun -p bmm --time=12:00:00 --nodes=1 \
    --cpus-per-task 2 --mem 100GB --pty /bin/bash
```

To activate the Rstudio and the conda environemnt use:

```[!]
module load rstudio-server
conda activate r-env
rstudio-launch
```
You should then see a message like this:
```
Run the following command in a new terminal on your computer:

    ssh -L12345:aa10:12345 username@farm.hpc.ucdavis.edu
```
- *Copy the newly generated ssh and paste it in a new terminal on your computer.* *Do not close your current terminal.*


You should also see a message like this:
```
Then, on your computer, navigate your browser to:

    URL: http://localhost:12345
    Username: username
    Password: very-long-pass-word-copy-and-past-in-brower
```
- *Copy and paste the url into your web browser of choice. When prompted for username and password, use the provided username and password.*

You should then be able to use Rstudio on Farm.