Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to configure a Shiny Server on Amazon’s EC2 cloud service

1. Configure the Amazon’s EC2 cloud service (one year for free)

Here you can see a guide to create and account and configure it:

2. Connect by ssh in order to install R, Shiny, etc

To this end, you need to write:

$ chmod 400 yourkey.pem
$ ssh -i "yourkey.pem"

Then you need to install R, Shiny, etc.:

$ sudo apt-get update
$ sudo apt-get install r-base
$ sudo apt-get install r-base-dev

$ sudo su - \
-c "R -e \"install.packages('shiny', repos='')\""

$ sudo su - \
-c "R -e \"install.packages('fpp', repos='')\""

$ sudo su - \
-c "R -e \"install.packages('rmarkdown', repos='')\""

$ sudo su - \
-c "R -e \"install.packages('ggplot2', repos='')\""

$ sudo apt-get install gdebi-core
$ wget
$ sudo gdebi shiny-server-

hint: you need to rewrite the version number of the shiny-server with the last one (

We can test the shiny-server. In order to do this, we need:

  • to install a sample app
$ sudo /opt/shiny-server/bin/deploy-example default
  • to open the port, so your Shiny server can be accessed from the outside world. By default, this is port 3838. Go to Instances, select your instance, and then click on the Security Group in the instance’s detail section. Click on the Inbound tab. By default, AWS instances launched with the wizard have only port 22 open, which is needed to SSH in. No wonder we cannot access our instance! Click on Edit and add a custom TCP rule to open port 3838 from anywhere.

Open your favorite browser and enter the following address:

hint: replace the IP address (, in my example) with the address of your instance, which is the same with which you connected to your instance.

If you want users don't specify the number of the port (3838), you can change it to 80 in the shiny configuration. For this:

$ sudo nano /etc/shiny-server/shiny-server.conf

and change the number 3838 by 80, press Ctrl + X and Yes. Lastly, you need to restart the server

$ sudo systemctl restart shiny-server

and open your port 80 in the AWS EC2 Security Group by adding a custom TCP rule for port 80, similar to what you did above for 3838.

Note: To write this section I've used a modified version of the text on

Finally, you can see here an example:

Extra details:

  • Copying folders from my computer to the server:
$ scp -r /Users/Sestelo/Dropbox/github/shiny_npregfast/ 

$ scp -r /Users/Sestelo/Dropbox/github/shiny_npregfast/
  • Moving files (server):
$ sudo mv /home/ubuntu/shiny_npregfast/ /srv/shiny-server/
  • Installing R packages in the server (in order to shiny apps work well). If you install them from console, the apps aren´t going to work because it install them in your local library (rstudio/shiny#862):
$ sudo su -   -c "R -e \"install.packages('npregfast', repos='')\"" 

Connecting to the server by means of Transmit app

The yourkey.pem file must be in the user folder (/Users/Sestelo/yourkey.pem)

In terminal, type:

$ chmod 700 yourkey.pem
$ ssh-add -K yourkey.pem

In Transmit (use SFTP) fill with:

  • server: the name of the domain used to access it (
  • username: ubuntu
  • the rest: nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment