This vignette walks through deploying a Reactor notebook as a Shiny application on shinyapps.io. First, we load the Reactor package:

For this vignette, we’ll use the Gaussian Processes example notebook provided in the package:

notebook <- reactor_example("gaussian_processes.Rmd")

If you’d like to start from scratch with a new notebook, you can run:

notebook <- ReactorNotebook$new()

server <- start_reactor(notebook)

Now that we have a notebook, we need to export it as a Shiny application. The export_shiny function takes a notebook and creates two files in a given directory: notebook.Rmd, which contains the Reactor notebook, and app.R, which launches the notebook as a Shiny application. Create a folder, here we call it app, and then run:

export_shiny(notebook, "./app")

The newly created file ./app/app.R contains the following:

# shinyApp

library(shiny)
library(reactor)

notebook <- ReactorNotebook$load('notebook.Rmd')

start_reactor_as_shiny(notebook)

If you open app.R in RStudio, it will recognize it as a Shiny application and the Run App button will appear above the editor. You can deploy the application to shinyapps.io using the built-in tools from RStudio.

Alternatively, you can deploy the application directly from R using the rsconnect package. The package’s “Getting Started” vignette describes how to do so in detail; we summarize the steps in this vignette as well.

First, load the rsconnect package and set the account name, token, and secret, which can be found on the Profile / Tokens page of your shinyapps.io account.

library(rsconnect)

rsconnect::setAccountInfo(name="<ACCOUNT>", token="<TOKEN>", secret="<SECRET>")

Next, deploy the application using the deployApp function, supplying an application name:

deployApp(appDir = "app", appName = "gaussian_processes")

Once the deployment is complete, the notebook will be available as an online Shiny application. The example notebook used here can be found at https://hsusmann.shinyapps.io/gaussian_processes/.