Skip to content

[NEW] Install R on Debian and Ubuntu and NEW] Deploy RStudio on Debian and Ubuntu #1457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/R/rstudio-server-login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/R/rstudio-server-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions docs/development/r/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
author:
name: Linode
email: [email protected]
description: ''
keywords: ["development", "r", "data science", "statistics"]
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
aliases: []
published: 2018-01-29
title: R
show_in_lists: true
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
author:
name: Sam Foo
email: [email protected]
description: 'RStudio Server is a the web based version of RStudio for a desktop environment. Gain access to your R development environment from anywhere in the world.'
og_description: 'RStudio Server is a the web based version of RStudio for a desktop environment. Gain access to your R development environment from anywhere in the world.'
keywords: ['R', 'statistic', 'R Foundation', 'data visualization']
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
modified: 2018-01-29
modified_by:
name: Linode
published: 2018-01-29
title: 'How to Deploy RStudio Server Using an NGINX Reverse Proxy'
---

## What is RStudio Server?

[RStudio](https://www.rstudio.com) is an integrated development environment (IDE) for [R](https://www.r-project.org/), an open source statistical computing language. It includes debugging and plotting tools that make it easy to write, debug, and run R scripts. The IDE is available in both desktop and server configurations. By hosting the server configuration (RStudio Server) on a Linode, you can access the IDE from any computer with internet access. Since data analysis often uses large datasets and can be computationally expensive, keeping your data and running R scripts from a remote server can be more efficient than working from your personal computer. In addition, a professional edition is available that allows project sharing and simultaneous code editing for multiple users.

## Before You Begin

This guide assumes an R installation version of R 3.0.1+ and will show how to install RStudio Server 1.1. See our guide on [installing R on Ubuntu and Debian](/docs/development/r/how-to-install-r-on-ubuntu-and-debian) for steps on installing the latest version of R.

The steps in this guide are for Ubuntu 16.04 and should be adapted to your specfic distribution installation.

## Install RStudio Server

1. Download RStudio 1.1:

wget https://download2.rstudio.org/rstudio-server-1.1.414-amd64.deb

2. Install and use the gDebi package installer for the downloaded Debian package file:

sudo apt install gdebi
sudo gdebi rstudio-server-1.1.414-amd64.deb

If successful, the output should show `rstudio-server.service` as active.

{{< output >}}
Created symlink from /etc/systemd/system/multi-user.target.wants/rstudio-server.service to /etc/systemd/system/rstudio-server.service.
● rstudio-server.service - RStudio Server
Loaded: loaded (/etc/systemd/system/rstudio-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-01-23 21:18:44 UTC; 1s ago
Process: 13676 ExecStart=/usr/lib/rstudio-server/bin/rserver (code=exited, status=0/SUCCESS)
Main PID: 13677 (rserver)
CGroup: /system.slice/rstudio-server.service
└─13677 /usr/lib/rstudio-server/bin/rserver

Jan 23 21:18:44 localhost systemd[1]: Starting RStudio Server...
Jan 23 21:18:44 localhost systemd[1]: Started RStudio Server.
{{< /output >}}

3. In a browser, navigate to your Linode's public IP address on port 8787 (i.e. `public-ip:8787`). Use your Unix user's username and password to log in when prompted:

![RStudio Server Login](/docs/assets/R/rstudio-server-login.png)

4. Because you will be accessing RStudio through a reverse proxy, set RStudio Server to listen on localhost instead of a public IP. Open `rserver.conf` in a text editor and add the following content:

{{< file-excerpt "/etc/rstudio/rserver.conf" >}}
# Server Configuration File
www-address=127.0.0.1
{{< /file-excerpt >}}

5. You can also set the configuration for each individual session. For example, the default session timeout is two hours. Change this to 30 minutes to conserve server resources:

{{< file-excerpt "/etc/rstudio/rsession.conf" >}}
# R Session Configuration File
session-timeout-minutes=30
{{< /file-excerpt >}}

6. Check your configuration:

sudo rstudio-server verify-installation

7. If there are no issues, restart RStudio server to apply the changes:

sudo rstudio-server restart

## Set Up the Reverse Proxy

Running Rstudio server behind a reverse proxy offers benefits such as being able to pick the URL endpoints and load balancing.

1. Install NGINX:

sudo apt install nginx

2. Open `nginx.conf` in a text edirot and add the following configuration:

{{< file-excerpt "/etc/nginx/nginx.conf" nginx >}}
http {
# Basic Settings
# ...

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
{{< /file-excerpt >}}

3. Create an NGINX configuration in `/etc/nginx/conf.d/` called `rstudio.conf` with the following configuration. Replace `example.com` with the public IP address or FDQN of your Linode:

{{< file-excerpt "/etc/nginx/conf.d/rstudio.conf" nginx >}}
server {
listen 80;
listen [::]:80;

server_name example.com;

location / {
proxy_pass http://localhost:8787/;
proxy_redirect http://localhost:8787/ $scheme://$host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
}
}
{{< /file-excerpt >}}

4. Check the NGINX configuration:

sudo nginx -t

5. If there are no errors, restart NGINX to apply the changes:

sudo systemctl restart nginx

6. In a browser, navigate to the public IP or FDQN of your Linode. After logging in, the RStudio IDE should be available from your browser:

![Rstudio Screen](/docs/assets/R/rstudio-server-page.png)

{{< note >}}
If Rstudio does not load in the browser, you may need to clear your browser cache.
{{< /note >}}
153 changes: 153 additions & 0 deletions docs/development/r/how-to-install-r-on-ubuntu-and-debian.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
author:
name: Sam Foo
email: [email protected]
description: 'R is a programming language commonly used for statistical analysis and data visualization. Learn how to install the base R package on your Linode.'
og_description: 'R is a programming language commonly used for statistical analysis and data visualization. Learn how to install the base R package on your Linode.'
keywords: ['R', 'statistics', 'R Foundation', 'data visualization']
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
modified: 2018-01-29
modified_by:
name: Linode
published: 2018-01-29
title: 'How to install R on Ubuntu and Debian'
---


## What is R?

[R is a programming language](https://www.r-project.org/about.html) used for statistical analysis in addition to data visualization. The language is highly extensible through the [Comprehensive R Archive Network(CRAN)](https://cran.r-project.org/), which hosts more than 10,000 R packages for producing publication quality figures, specialized computational tools, and more.

Although R can be installed through the default Debian or Ubuntu repository, the method outlined in this guide will ensure that you install the most up-to-date stable release.

## Install R on Ubuntu 16.04 and Debian 9

1. Open `/etc/apt/sources.list` and add the following line to the end of the file:

Ubuntu:

deb http://cran.rstudio.com/bin/linux/ubuntu xenial/

Debian:

deb http://cran.rstudio.com/bin/linux/debian stretch-cran34/

2. Add the key ID for the CRAN network:

[UBuntu GPG key](https://cran.rstudio.com/bin/linux/ubuntu/):

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

[Debian GPG key](https://cran.rstudio.com/bin/linux/debian/):

sudo apt install dirmngr
sudo apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'

3. Update the repository:

sudo apt update

4. Install the R binaries:

sudo apt install r-base

## Download Packages from CRAN

1. Open the R interpreter:

R

2. The interpreter will open with some information about the version. Enter `install.packages("ggplot2")`:

{{< output >}}
R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 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.

Natural language support but running in an English locale

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.

> install.packages("ggplot2")
{{< /output >}}

3. A list of available mirrors should appear. Pick the closest location to maximize transfer speeds:

{{< output >}}
--- Please select a CRAN mirror for use in this session ---
HTTPS CRAN mirror

1: 0-Cloud [https] 2: Algeria [https]
3: Australia (Canberra) [https] 4: Australia (Melbourne 1) [https]
5: Australia (Melbourne 2) [https] 6: Australia (Perth) [https]
7: Austria [https] 8: Belgium (Ghent) [https]
9: Brazil (PR) [https] 10: Brazil (RJ) [https]
11: Brazil (SP 1) [https] 12: Brazil (SP 2) [https]
13: Bulgaria [https] 14: Canada (MB) [https]
15: Chile 1 [https] 16: Chile 2 [https]
17: China (Beijing) [https] 18: China (Hefei) [https]
19: China (Guangzhou) [https] 20: China (Lanzhou) [https]
21: China (Shanghai) [https] 22: Colombia (Cali) [https]
23: Czech Republic [https] 24: Denmark [https]
25: East Asia [https] 26: Ecuador (Cuenca) [https]
27: Estonia [https] 28: France (Lyon 1) [https]
29: France (Lyon 2) [https] 30: France (Marseille) [https]
31: France (Montpellier) [https] 32: France (Paris 2) [https]
33: Germany (Göttingen) [https] 34: Germany (Münster) [https]
35: Greece [https] 36: Iceland [https]
37: India [https] 38: Indonesia (Jakarta) [https]
39: Ireland [https] 40: Italy (Padua) [https]
41: Japan (Tokyo) [https] 42: Japan (Yonezawa) [https]
43: Malaysia [https] 44: Mexico (Mexico City) [https]
45: New Zealand [https] 46: Norway [https]
47: Philippines [https] 48: Serbia [https]
49: Singapore (Singapore 1) [https] 50: Spain (A Coruña) [https]
51: Spain (Madrid) [https] 52: Sweden [https]
53: Switzerland [https] 54: Taiwan (Chungli) [https]
55: Turkey (Denizli) [https] 56: Turkey (Mersin) [https]
57: UK (Bristol) [https] 58: UK (Cambridge) [https]
59: UK (London 1) [https] 60: USA (CA 1) [https]
61: USA (IA) [https] 62: USA (IN) [https]
63: USA (KS) [https] 64: USA (MI 1) [https]
65: USA (NY) [https] 66: USA (OR) [https]
67: USA (TN) [https] 68: USA (TX 1) [https]
69: Vietnam [https] 70: (HTTP mirrors)


Selection:
{{< /output >}}

4. When quitting the interpreter, you will be prompted to save the workspace image. If you choose yes, this will save all the user defined objects for the next session:

{{< output >}}
> q()
Save workspace image? [y/n/c]:
{{< /output >}}

## RStudio IDE Desktop

The R interpreter lacks features such as a debugger which may be needed for larger projects. RStudio is an IDE that comes with many tools for development right out of the box.

1. Download RStudio as a Debian package:

wget https://download1.rstudio.org/rstudio-xenial-1.1.414-amd64.deb

2. Install the package:

sudo dpkg -i rstudio-xenial-1.1.414-amd64.deb

{{< note >}}
If there are missing dependencies, those can be installed with the following command:

sudo apt install -f
{{< /note >}}