How to launch a Shiny app

This article discusses running an app in a separate process and live reloading of apps.
Published

June 28, 2017

In previous articles[1, 2] you’ve been calling runApp to run the example applications. This function starts the application and opens up your default web browser to view it. The call is blocking, meaning that it prevents traditional interaction with the console while the application is running.

To stop the application you simply interrupt R – you can do this by pressing the Ctrl-C in some R front ends, or the Escape key in RStudio,or by clicking the stop button if your R environment provides one.

Running in a Separate Process

If you don’t want to block access to the console while running your Shiny application you can also run it in a separate process. You can do this by opening a terminal or console window and executing the following, where ~/shinyapp should be replaced with the path to your application:

R -e "shiny::runApp('~/shinyapp')"

By default runApp starts the application on a randomly selected port. For example, it might start on port 4700, in which case you can connect to the running application by navigating your browser to http://localhost:4700.

In other articles, we discuss some techniques for debugging Shiny applications, including the ability to stop execution and inspect the current environment. To combine these techniques with running your applications in a separate terminal session, you’ll need to call runApp from an interactive R session, instead of with the method here.

Live Reloading

When you make changes to your underlying user interface definition or server script you don’t need to stop and restart your application to see the changes. Simply save your changes and then reload the browser to see the updated application in action.

One qualification to this: when a browser reload occurs Shiny explicitly checks the timestamp of the app.R file to see if it needs to be re-sourced. Shiny isn’t aware of other scripts or data files that change, so if you use those files and modify them, a full stop and restart of the application is needed.