You can now build a useful Shiny app, but can you share it with others? This lesson will show you several ways to share your Shiny apps.
When it comes to sharing Shiny apps, you have two basic options:
Share your Shiny app as two files:
ui.R. This is the simplest way to share an app, but it works only if your users have R on their own computer (and know how to use it). Users can use these scripts to launch the app from their own R session, just like you’ve been launching the apps.
Share your Shiny app as a web page. This is definitely the most user friendly way to share a Shiny app. Your users can navigate to your app through the internet with a web browser. They will find your app fully rendered, up to date, and ready to go.
Anyone with R can run your Shiny app. They will need a copy of your
ui.R files, as well as any supplementary materials used in your app (e.g.,
www folders or
To send your files to another user, email the files (perhaps in a zip file) or host the files online.
Your user can place the files into an app directory in their working directory. They can launch the app in R with the same commands you used on your computer.
# install.packages("shiny") library(shiny) runApp("census-app")
Shiny has three built in commands that make it easy to use files that are hosted online:
runUrl will download and launch a Shiny app straight from a weblink.
library(shiny) runUrl( "<the weblink>")
If you don’t have your own web page to host the files at, you can host your the files for free at www.github.com.
Github is a popular project hosting site for R developers since it does more than just host files. Github provides many features to support collaboration, such as issue trackers, wikis, and close integration with the git version control system. To use Github, you’ll need to sign up (it’s free) and choose a user name.
To share an app through Github, create a project repository on Github. Then store your
ui.R files in the repository, along with any supplementary files that the app uses.
Your users can launch your app by running:
runGitHub( "<your repository name>", "<your user name>")
If you want an anonymous way to post files online, Github offers a pasteboard service for sharing files at gist.github.com. You don’t need to sign up for Github to use this service. Even if you have a Github account, Gist can be a simple, quick way to share Shiny projects.
To share your app as a Gist:
ui.Rfiles to the Gist web page.
Once you’ve made a Gist, your users can launch the app with
runGist("<gist number>") where
"<gist number>" is the number that appears at the end of your Gist’s web address.
Here’s an example of an app hosted as a Gist. You could launch this app with:
All of the above methods share the same limitation. They require your user to have R and Shiny installed on their computer.
However, Shiny creates the perfect opportunity to share output with people who do not have R (and have no intention of getting it). Your Shiny app happens to be one of the most widely used communication tools in the world: a web page. If you host the app at its own URL, users can visit the app (and not need to worry about code).
If you are familiar with web hosting or have access to an IT department, you can host your Shiny apps yourself.
If you’d prefer an easier experience or need support, RStudio offers three ways to host your Shiny app as a web page:
The easiest way to turn your Shiny app into a web page is to use shinyapps.io, RStudio’s hosting service for Shiny apps.
shinyapps.io lets you upload your app straight from your R session to a server hosted by RStudio. You have complete control over your app including server administration tools. You can find out more about shinyapps.io by visiting shinyapps.io.
Shiny Server is a companion program to Shiny that builds a web server designed to host Shiny apps. It’s free, open source, and available from Github.
Shiny Server is a server program that Linux servers can run to host a Shiny app as a web page. To use Shiny Server, you’ll need a Linux server that has explicit support for Ubuntu 12.04 or greater (64 bit) and CentOS/RHEL 5 (64 bit). If you are not using an explicitly supported distribution, you can still use Shiny Server by building it from source.
You can host multiple Shiny applications on multiple web pages with the same Shiny Server, and you can deploy the apps from behind a firewall.
To see detailed instructions for installing and configuring a Shiny Server, visit the Shiny Server guide.
Shiny Server will get your app to the web and take care of all of your Shiny publishing needs. However, if you use Shiny in a for-profit setting, you may want to give yourself the server tools that come with most paid server programs, such as
If so, check out Shiny Server Pro, RStudio’s paid professional version of Shiny Server.
Shiny apps are easy to share. You can share your app as a couple of R scripts, or as a fully functioning web app with its own URL. Each method has its own advantages.
runGistmake it simple to share and retrieve Shiny files from web links.
Congratulations. You’ve worked through the entire Shiny development process. You can build a sophisticated, reactive app, deploy it, and share it with others. Users can interact with your data and follow your stories in a new way.
The next step is to practice, and then explore the advanced features of Shiny.
The Shiny Dev Center also includes an articles section for continuing education. Each article examines an intermediate to advanced Shiny topic in depth.
You now know enough to build your own Shiny apps. See what you can do!
We love it when R users help each other, but RStudio does not monitor or answer the comments in this thread. If you'd like to get specific help, we recommend the Shiny Discussion Forum for in depth discussion of Shiny related questions and How to get help for a list of the best ways to get help with R code.comments powered by Disqus