How to publish a Shiny app? An example with shinyapps.io

Antoine Soetewey 2020-05-29 5 minute read

Introduction

The COVID-19 virus led many people to create interactive apps and dashboards. A reader recently asked me how to publish a Shiny app she just created. Similarly to a previous article where I show how to upload R code on GitHub, I thought it would be useful to some people to see how I publish my Shiny apps so they could do the same.

Before going through the different steps required to deploy your Shiny app online, you can check the final result with my apps here.

Note 1: The screenshots have been taken on MacOS and I have not tested it on Windows. Do not hesitate to let me know in the comments whether it is similar or not on other operating systems.

Note 2: There are other ways to publish your app (with Docker for example), but the method shown below is easy (in my opinion) and works well.

Prerequisite

I personally use the shinyapps.io platform to deploy my Shiny apps. So in order to follow this guide you will first need to create an account (if you do not already have one).

They offer a free plan, but you are limited to 5 active applications and a monthly usage of 25 active hours.

For your information, if you make your app available to a wide audience, expect to exceed the monthly cap of active hours quite quickly. To increase the monthly limit (or to publish more than 5 apps), you will need to upgrade your plan to a paying one.

Step-by-step guide

Below the steps to follow in pictures.

Step 1: Open RStudio and create a new Shiny app:

Step 2: Give it a name (without space), choose where to save it and click on the Create button:

Step 3: In the same way as when you open a new R Markdown document, the code for a basic Shiny app is created. Run the app by clicking on the Run App button to see the result:

Step 4: The basic app opens, publish it:

Step 5: If it is your first Shiny app, the box “Publish From Account” should be empty. Click on “Add New Account” to link the shinyapps.io account you just created:

Step 6: Click on the first alternative (ShinyApps.io):

Step 7: Click on the link to your ShinyApps account:

Step 8: Click on the Dashboard button to log in into your account:

Step 9: Click on your name and then on Tokens

Step 10: If this is your first app, there should be no token already created. Create one by clicking on the Add Token button. Then Click on the Show button:

Step 11: Click on the Show Secret button:

Step 12: Now the code is complete (nothing is hidden anymore). Click on the Copy to clipboard button:

Step 13: Copy the code and click on the OK button:

Step 14: Go back to RStudio, paste the code in the console and run it:

Your computer is now authorized to deploy applications to your shinyapps.io account.

Step 15: Go back to the window where you can publish your app, choose a title (without space) and click on the Publish button:

Step 16: After several seconds (depending on the weight of your app), the Shiny app should appear in your internet browser:

Step 17: You can now edit the app (or replace the entire code by another of your app), and run the app again by clicking on the Run App button. For this illustration, I just added a link for more information in the side panel:

Step 18: Check that the modifications have been taken into account (the link appears in the side panel as expected) and republish your app:

Step 19: Click on the Publish button:

Step 20: Your app is live! You can now share it and everyone with the link will be able to use it:

Additional notes

Settings of your app

If you need to change the settings of your Shiny app, go to your shinyapps.io dashboard and click on the app you just created to access the settings:

See the different settings in the tabs located at the top of the windows, and see the link to the app next to the URL field:

Publish your dataset

It is often the case that your Shiny app uses a dataset that is not loaded in R by default (it uses one of your dataset that is saved locally on your computer for instance).

To make the app work with your data, you will also need to publish the data when publishing your app (check the checkbox corresponding to your data):

Publish your dataset together with the app

If you would like to have more flexibility, another way to be able to use an external dataset in your app is to host it online:

  • if you have a website, you can easily publish it through your website
  • if you do not have a website, you can host the dataset via GitHub (if you do not have an account, it is a good time to create one!)

The last step is then to import the data via that new URL (put the data import in the code of your app).

Conclusion

Thanks for reading.

I hope this tutorial helped you to publish your first Shiny app.

As always, if you have a question or a suggestion related to the topic covered in this article, please add it as a comment so other readers can benefit from the discussion.



Liked this post?

  • Get updates every time a new article is published (no spam and unsubscribe anytime):

  • Support the blog
  • Share on: