Typically, you create a Shiny application not only for yourself, but also for other users. There are a two main ways to distribute your app; either you let users download your application, or you deploy it on the web.
By offering the option to download your final Shiny application, other users can run your app locally. Actually, there are four ways to deliver your app this way. No matter which way you choose, it is important that the user has installed R and the Shiny
package on his/her computer.
Gist is a public code sharing pasteboard from GitHub. To share your app this way, it is important that both the ui.R
file and the server.R
file are in the same Gist and have been named correctly. Take a look at the following screenshot:
There are two options to run apps via Gist. First, just enter runGist("Gist_URL")
in the console of RStudio; or second, just use the Gist ID and place it in the shiny::runGist("Gist_ID")
function.
Gist is a very easy way to share your application, but you need to keep in mind that your code is published on a third-party server.
The next way to enable users to download your app is through a GitHub repository:
To run an application from GitHub, you need to enter the command, shiny::runGitHub("Repository_Name", "GitHub_Account_Name")
, in the console:
There are two ways to share a Shiny application by zip file. You can either let the user download the zip file over the web, or you can share it via email, USB stick, memory card, or any other such device. To download a zip file via the Web, you need to type runUrl("Zip_File_URL")
in the console.
Certainly, a much more labor-intensive but also publically effective way is to create a complete R package for your Shiny application. This especially makes sense if you have built an extensive application that may help many other users. Another advantage is the fact that you can also publish your application on CRAN. Later in the book, we will show you how to create an R package.
After showing you the ways users can download your app and run it on their local machines, we will now check the options to deploy Shiny apps to the web.
http://www.shinyapps.io/ is a Shiny app-hosting service by RStudio. There is a free-to-use account package, but it is limited to a maximum of five applications, 25 so-called active hours, and the apps are branded with the RStudio logo. Nevertheless, this service is a great way to publish one's own applications quickly and easily to the web.
To use http://www.shinyapps.io/ with RStudio, a few R packages and some additional operating system software needs to be installed:
RTools
(If you use Windows)GCC
(If you use Linux)XCode
Command Line Tools (If you use Mac OS X)devtools
R packageshinyapps
packageSince the shinyapps
package is not on CRAN, you need to install it via GitHub by using the devtools
package:
if (!require("devtools")) install.packages("devtools") devtools::install_github("rstudio/shinyapps") library(shinyapps)
When everything that is needed is installed ,you are ready to publish your Shiny apps directly from the RStudio IDE. Just click on the Publish icon, and in the new window you will need to log in to your http://www.shinyapps.io/ account once, if you are using it for the first time. All other times, you can directly create a new Shiny app or update an existing app.
After clicking on Publish, a new tab called Deploy opens in the console pane, showing you the progress of the deployment process. If there is something set incorrectly, you can use the deployment log to find the error.
When the deployment is successful, your app will be publically reachable with its own web address on http://www.shinyapps.io/.
There are two editions of the Shiny Server software: an open source edition and the professional edition. The open source edition can be downloaded for free and you can use it on your own server. The Professional edition offers a lot more features and support by RStudio, but is also priced accordingly. In Chapter 9, R for your Organization – Managing the RStudio Server we will show you how to set up a self-hosted Shiny server with the open source version of the software.