Shiny by RStudio

How to launch a Shiny app

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 timestamps of the ui.R and server.R files to see if they need 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.

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