RStudio Server, Linux(Ubuntu), WSL(Windows Subsystem for Linux), and Docker
If I want to use RStudio Server, I need Linux as OS. Windows users like me need to set up WSL(Windows Subsystem for Linux) for RStudio Server. First of all, make sure if your Windows is the latest version.
- Setup WSL
Check
Virtual Machine Platform
and Windows Subsystem for Linux
. Then Restart your device.
- Change the WSL version to 2
# In the Windows PowerShell as Administrator
wsl --set-default-version 2
# See https://aka.ms/wsl2kernel if you have an issue
- Install Ubuntu
- Setup Ubuntu account
- Update Ubuntu
# In the Ubuntu
sudo apt update
sudo apt upgrade -y
# You cannot use ctrl+V in the Ubuntu. Instead Use the right click
- Install the latest R and RStudio Server
# See https://cran.r-project.org/bin/linux/ubuntu/
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
sudo apt update
sudo apt install -y r-base r-base-core r-recommended r-base-dev gdebi-core build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev
## Install RStudio Server ##
wget https://rstudio.org/download/latest/stable/server/bionic/rstudio-server-latest-amd64.deb
sudo gdebi rstudio-server-latest-amd64.deb
- Run RStudio Server
sudo rstudio-server start
In the Web browser, http://localhost:8787
, and type username and password you already created for the Ubuntu account.
- Tip and Close RStudio Server
# Some packages may cause an install issue. You may need an dependency.
# https://jeroen.cran.dev/V8/
sudo apt-get install -y libv8-dev
# Then install R package V8
## To Close RStudio Server ##
sudo rstudio-server stop
- Docker
Run Docker. you can find Images tab in the left panel. Docker needs an image to run instead of files. We need Rstudio image.
Go to DockerHub. Then type
rocker
in the Search. You can find rocker/rstudio
. Copy docker pull rocker/rstudio
, then paste it in the Powershell.
You can find
rocker/rstudio
in the image tab of docker.
Click Run for it. In the option, choose Container names. For example, "rstudio-1". Then configure 4-digit Local Host like 1001.
Now you can see
rstudio-1
in the Containers/Apps tab. In the web browser, type http://localhost:1001/
. Both ID and Password are rstudio which was created by image creators.
- Update image for your project
# In the Powershell, check docker containers
docker ps -a
docker commit {Container ID} {New image name}
#ex# docker commit 40b8d16b7dba rstudio-2
Now you can find rstudio-2
in the image tab. This rstudio-2
has the same environment you already created. Just run this without typing the code in Ubuntu. If you make multiple containers, you can run multiple Rs at the same time.
- To Stop Vmmem
# In the Powershell
wsl --shutdown
- To setup xfce4
# In the Ubuntu
cat /etc/resolv.conf
# It will show nameserver.
nano ~/.bashrc
# It will open nano editor. In the nano, scroll down the bottom. Then,
export DISPLAY={the nameserver above}:0
#ex# export DISPLAY=100.00.000.1:0
# Save it with Ctrl+X. In Ubuntu
source ~/.bashrc
echo $DISPLAY
# If it show the nameserver, then type
startxfce4
However, the namesever can change. It is tiresome to change it everytime.
# In Nano, delete "export DISPLAY={the nameserver above}:0".
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
GDK_SCALE=1
# Then Save it.