knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

library(details)

reactor

Lifecycle: maturing R-CMD-check pkgdown Reactor Covrpage Summary

When developing Shiny apps there is a lot of reactivity problems that can arise when one reactive or observe element triggers other elements. In some cases these can create cascading reactivity (the horror). The goal of reactor is to diagnose these reactivity problems and then plan unit tests to avert them during development to make development less painful.

Installation

And the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("yonicd/reactor")

Usage

Reactor is a pipeline driven api where the user does not need to learn RSelenium in order to be able to drive their applications

Initializing Reactor

Start by creating a reactor class object

library(reactor)
obj <- init_reactor()
obj

Populating Specifications

You can see it is expecting to be populated by two objects

Reactor comes with functions to help you create these specifications

obj <- obj%>%
  set_runapp_args(
    appDir = system.file('examples/good_app.R',package = 'reactor')
  )%>%
  set_chrome_driver()

```{details, echo = FALSE,details.lang = 'yml',details.summary = 'reactor object'} obj

If you want turn off headless mode you can update the object

```r
obj <- obj%>%
  set_chrome_driver(
     opts = chrome_options(headless = FALSE)
  )

```{details, echo = FALSE, details.lang = 'yml',details.summary = 'reactor object'} obj

### Starting Reactor

Once we have specifications in place we can start reactor using `start_reactor()`. 

```r
obj%>%
  start_reactor()

Interacting with the application

Now that the app is running we can send to the webdriver to interact with the application

obj%>%
  set_id_value('n',500)

The user can use the following utility functions to interact and query with an application

Inject:

Query:

Closing Reactor

To safely close reactor and all the child processes use kill_app():

obj%>%
  kill_app()

Pipeline Operations

Because each function is returning the reactor object it is simple to create reactor pipelines.

Reactor will wait for shiny to finish each action before proceeding to the next one.

init_reactor()%>%
  set_runapp_args(
    appDir = system.file('examples/good_app.R',package = 'reactor')
  )%>%
  set_chrome_driver()%>%
  start_reactor()%>%
  set_id_value('n',500)%>%
  set_id_value('n',300)%>%
  kill_app()

Testing Expectations

Finally reactor tests reactivity expectations in a testthat framework using the builtin expect_reactivity() function

init_reactor()%>%
  set_runapp_args(
    appDir = system.file('examples/good_app.R',package = 'reactor')
  )%>%
  set_chrome_driver()%>%
  start_reactor()%>%
  set_id_value('n',500)%>%
  expect_reactivity('hist',1)%>%
  set_id_value('n',200)%>%
  expect_reactivity('hist',2)%>%
  kill_app()


yonicd/reactor documentation built on Jan. 20, 2021, 4:40 a.m.