Module 6.2
Sharing Your App
- Sign up for a free account on ShinyApps.io
- Install rsconnect so that you can publish to shinyapps.io (
install.packages("rsconnect")
) - Install renv and familiarize yourself with its basic purpose and features (
install.packages("renv")
)
Now that you have your Shiny app, how can you share it with others? The simplest and most logical thing to do is to publish it as a web page. After all, sharing your app on the web is sort of the point of making a web app and doing so is an essential if you want to share your apps with a broader set of users who do not know how to use R or and/or Shiny. There are many different ways to publish your app but the best way when you are getting started is ShinyApps.io.
You also may want to share your app with collaborators by sending them your R script and supporting files before you make your app public or available to a broader group of users. There are many ways to share your Shiny app files but the two we are going to cover are sending the files via email or sharing them on GitHub.
Note that while I am covering methods of sharing your code with others, your are not required to do so for this course. The only requirement is sharing your application as a web app via ShinyApps.io and then either writing a short essay about the app or demoing the app in a short video. Then you will submit your code via a private repo via GitHub classroom as you have been doing for the previous assignments.
Publishing your app on ShinyApps.io
Once it is ready to go, publishing your app to ShinyApps.io is super-easy. Make sure that you have the rsconnect
package installed. Then, in RStudio, go to Tools > Global Options and select Publishing. Select Connect, ShinyApps.io and follow the instructions for retrieving and entering your token.
Once that is set up, open your app.R file. At the top of your Source window, you should see a little blue circle with arrows surrounding it that says “Publish the application or document” when you hover over it. Click that and, if prompted to do so, install any required updates.
Next you will be prompted for which files you want to upload. Just select the essential files that you need for the app like the app.R file and any supporting files like a .csv file with the data the app needs or helper scripts. No need to upload ancillary files like your prep file or .Rprofile.
Then hit Publish and that should be it! Here is a good set of step-by-step instructions in case you happen to get stuck.
Using the renv
package to record your R environment
One problem you will frequently run into with R Shiny apps is that they can break as a result of package updates and new R installations. One way to prevent this from happening is to use the renv
package, which records your R environment at the time you made the app.
To do this, make sure renv
is installed. Then type renv::init()
in your console. Next, type ren::snapshot()
. At this point, renv
will give you a list of the packages and versions being used by the app. If everything looks good, type ‘y’ and renv
will record the environment. When you come back to work on the app later, you can choose whether to update the packages, but if doing so breaks the app you the option of restoring the earlier environment by typing renv::restore()
.