Article

Deploy an RStudio Server on AWS

RStudio Server lets users be able to access RStudio anywhere only if they have a web browser. It makes remote cooperation more easily, especially in this COVID pandemic. And, AWS is a powerful cloud computing platform which has various plans for data scientists to choose.

Set up an AWS instance

  1. We need to launch an AWS instance first. Select Launch a virtual machine.

Launch AWS

  1. Choose your desired VM system. Here I select Ubuntu 20 to obtain the newest R (4.0.2).

Choose VM

  1. Choose your desired VM specs. You can use free-trial one or high-performance one.

Choose Specs

  1. Click the Next: Configue Instance Details.

  2. Click the Create new IAM role. Create an IAM role as rstudio by the following JSON code. Then select the rstudio at the IAM role. Click the Next: Add Storage.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:ListBucket"],
      "Resource": ["arn:aws:s3:::rstatsdata"]
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:DeleteObject"
      ],
      "Resource": ["arn:aws:s3:::rstatsdata/*"]
    }
  ]
}
  1. Click the Next: Add Tags.

  2. Click the Configure Security Group.

  3. Configure the settings as the Screenshot.

Configure Security Group

  1. Click the Review and Launch and View Instance. It might ask user to save the SSH key. Please save it at a save place. We will use it later.

  2. Now you can access the instance in the Running Instances tab.

Instance Panel

Connect to the instance

  1. Open your terminal and cd to the folder you saved the SSH key. Type
ssh -i SSHkey.pem ubuntu@yourpublicDNSoftheInstance
  • type yes when you are asked Are you sure you want to continue connecting (yes/no/[fingerprint])?

Install R

  1. I got reference from How to Install R on Ubuntu 20.04
sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

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 install r-base
  1. Check the R version
R --version # R version 4.0.2 (2020-06-22) -- "Taking Off Again"

Install RStudio Server

  1. Just as the RStudio Server Webpage, type in terminal:
sudo apt-get install gdebi-core
wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-1.3.1073-amd64.deb
sudo gdebi rstudio-server-1.3.1073-amd64.deb

Create Login User

  1. To set up a new user, you can do
sudo useradd username
sudo passwd username
  1. IMPORTANT: we need to create the corresponding folder under the /home path.
sudo mkdir /home/username
sudo chown -R username username

Launch the RStudio Server

  1. Find the IPv4 Public IP in the instance information.

  2. Open a web browser and type in the IPv4address:8787.

  3. Enter the username and password you created just now.

  4. The RStudio Server should work now.

RStudio Server

Some Errors

  1. When you install package tidyverse, you may meet the following error:
ERROR: dependencies ‘httr’, ‘rvest’, ‘xml2’ are not available for package ‘tidyverse’
* removing ‘/home/ssc/R/x86_64-pc-linux-gnu-library/4.0/tidyverse’
Warning in install.packages :
  installation of package ‘tidyverse’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpicB0nC/downloaded_packages’
  • Solution: Type this in your terminal
sudo apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev
  1. When install package xlsx, you need Java and rJava installed.
  • Solution: I got reference from hannarud
    • check the Java status java -version
    • if it shows there is no java command then run these commands:
    sudo apt-get install default-jre
    sudo apt-get install default-jdk
    
    • Then make the R and Java associated
    sudo R CMD javareconf
    
    • Install RJava
    sudo add-apt-repository ppa:marutter/c2d4u3.5
    sudo apt-get update
    sudo apt-get install r-cran-rjava
    sudo apt-get install libgdal-dev libproj-dev