Skip to content
Closed
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/shiny/create-shiny-app.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/shiny/shiny-app.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/shiny/shiny-welcome.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/shiny/shiny3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 138 additions & 0 deletions docs/development/r/how-to-deploy-rshiny-server-on-ubuntu-and-debian.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
author:
name: Jared Kobos
email: [email protected]
description: 'Shiny is an R library that enables the creation of interactive data visualizations. This guide will show how to deploy an R Shiny app using Shiny Server.'
og_description: 'Shiny is an R library that enables the creation of interactive data visualizations. This guide will show how to deploy an R Shiny app using Shiny Server.'
keywords: ["r", "data visualization", "shiny", "web app"]
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
published: 2018-02-07
modified: 2018-02-07
modified_by:
name: Linode
title: 'How to Deploy Interactive R Apps with Shiny Server on Ubuntu and Debian'
external_resources:
- '[Shiny Server – Introduction](https://shiny.rstudio.com/articles/shiny-server.html)'
- '[Gallery of Shiny Apps](https://shiny.rstudio.com/gallery/)'
---

## What is Shiny?

[Shiny](https://shiny.rstudio.com/) is a library for the R programming language that allows you to create interactive web apps in native R, without needing to use web technologies such as HTML, CSS, or JavaScript frameworks. There are many ways to deploy Shiny apps to the web; this guide will use Shiny Server to host an example Shiny app on a Linode.

## Before You Begin

This guide uses RStudio to create an example Shiny app. If you do not have RStudio installed on your local computer, you can follow our [How to Deploy RStudio Using an NGINX Reverse Proxy](/docs/development/r/how-to-deploy-rstudio-server-using-an-nginx-reverse-proxy/) guide to set up a remote workstation on a Linode.

## Build a Test App

Shiny Server comes with pre-installed demo apps; however, in order to demonstrate the process of deploying an app, this guide will create an app locally and deploy it to a Shiny Server on a Linode.

1. Open RStudio and install the Shiny package:

install.packages('shiny')

2. In the **File** menu, select **Shiny Web App...** under **New File**. When prompted, choose a name for your project. Also select **Multiple File** and choose a directory to store the new app's files.

![Create New Shiny App](/docs/assets/shiny/create-shiny-app.png)

3. Two new files, `ui.R` and `server.R`, should be automatically opened in RStudio. These files are pre-filled with a demo app that will create an interactive histogram of R's built-in Old Faithful data set. Edit `server.R` to adjust the formatting of the histogram according to your tastes. For example, to change the bars to red with a black border:

hist(x, breaks = bins, col = 'red', border = 'black')

4. Test the project locally by clicking **Run App** in the upper right corner of the text editor.

5. Save the project and copy the files to your Linode. Replace `username` with your Unix account username and `linodeIP` with the public IP address or domain name of your Linode.

scp -r ~/shiny/Example username@linodeIP:/home/username

## Deploy to Remote Server

The steps in this section should be completed on your Linode.

### Install R

{{< content "install_r_ubuntu.md" >}}

### Add the Shiny Package

Use `install.packages()` to add the Shiny package:

sudo su - \
-c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""

### Install Shiny Server

1. Install `gdebi`:

sudo apt install gdebi-core

2. Download Shiny Server:

wget https://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.5.6.875-amd64.deb

3. Use `gdebi` to install the Shiny Server package:

sudo gdebi shiny-server-1.5.6.875-amd64.deb

4. The `shiny-server` service should start automatically. Check its status:

sudo systemctl status shiny-server.service

5. In a browser, navigate to your Linode's public IP address or FQDN on port 3838 (e.g. `example.com:3838`). You should see the Shiny Server welcome page:

![Shiny Server Welcome Page](/docs/assets/shiny/shiny-welcome.png)

### Deploy Your App

By default, Shiny Server uses `/srv/shiny-server/` as its site directory. Any Shiny apps in this directory will be served automatically.

1. Copy the example app directory into `/srv/shiny-server/`:

sudo cp -r Example/ /srv/shiny-server/

2. In a web browser, navigate to the app's address. Replace `example.com` with your Linode's public IP address or FQDN.

example.com:3838/Example

You should see your app displayed:

![Shiny Demo App](/docs/assets/shiny/shiny3.png)

### Configuration

Shiny Server's configuration file is stored at `/etc/shiny-server/shiny-server.conf`:

{{< file "/etc/shiny-server/shiny-server.conf" >}}
# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
listen 3838;

# Define a location at the base URL
location / {

# Host the directory of Shiny Apps stored in this directory
site_dir /srv/shiny-server;

# Log all Shiny output to files in this directory
log_dir /var/log/shiny-server;

# When a user visits the base URL rather than a particular application,
# an index of the applications available in this directory will be shown.
directory_index on;
}
}
{{< /file >}}

You can edit the port that Shiny Server will listen on, or change the site directory from which apps are served. The `directory_index` option allows visitors to view the contents of a directory by navigating to that path (for example, visiting `example.com:3838/sample-apps` will show a list of the example apps included in the Shiny Server installation). You can disable this behavior and hide the contents of directories by setting this option to `off`. For more information about configuring Shiny Server, see the official [Administrator's Guide](http://docs.rstudio.com/shiny-server/).

You will need to restart the `shiny-server` service after making changes to this file:

sudo systemctl restart shiny-server.service

## Next Steps

In order to keep the deployed app up to date with changes made in your local environment, you can consider using a more sophisticated deployment method such as Git or Rsync. Production deployments may also want to run Shiny Server behind a reverse proxy to make use of additional security and optimization features.
29 changes: 1 addition & 28 deletions docs/development/r/how-to-install-r-on-ubuntu-and-debian.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,7 @@ Although R can be installed through the default Debian or Ubuntu repository, the

## 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
{{< content "install_r_ubuntu.md" >}}

## Download Packages from CRAN

Expand Down
44 changes: 44 additions & 0 deletions docs/development/r/install_r_ubuntu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
author:
name: Sam Foo
email: [email protected]
description: 'Shortguide for installing R on Ubuntu'
license: '[CC BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0)'
keywords: []
modified: 2018-02-07
modified_by:
name: Sam Foo
title: "How to Install R on Ubuntu"
published: 2018-02-07
shortguide: true
show_on_rss_feed: false
---

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