knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(details)
library(reactor)

Simple App

Good App

In this app the plot is only rendered when the input$n is updated.

```{details,echo = FALSE,details.summary = 'Good App Script',details.open = TRUE} system.file('examples/good_app.R',package = 'reactor')

### Bad App

In this app the plot is rendered every time reactive elements in `input` are invalidated. 

  - This kind of setup can cause a lot of unwanted reactivity in larger apps with many elements.
  - We expect the reactive element that creates the plot to be invalidated more than once.
  - Notice how on the app initialization the chunk is rendered twice. 

```{details,echo = FALSE,details.summary = 'Bad App Script',details.open = TRUE}
system.file('examples/bad_app.R',package = 'reactor')

Testing

Using reactor we can test this expectation!

If we run the test on the good app the test will pass and if we run it on the bad app then it will fail signaling a problem.

To run a test you can use standard testthat functions like testthat::test_dir(), or you can use a reactor function reactor::test_app().

To use test_app just name the test file reactor-*.R instead of test-*.R this will have two benefits.

  1. covr will not pass the tests. This allows you to run the tests using test_dir which does have the necessary characteristics to run the tests.
  2. Allows the app tests to be isolated from the other unit tests thus allowing for covr and testthat to run on R CMD CHECK without needing to add skip_* into the app test files.

```{details,echo = FALSE,details.summary = 'Reactivity Test Script for Good App',details.open = TRUE} '../tests/testthat/reactor-rselenium_good.R'

```{details,echo = FALSE,details.summary = 'Reactivity Test Script for Bad App',details.open = TRUE}
'../tests/testthat/reactor-rselenium_bad.R'


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