knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(details)
library(reactor)
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')
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.
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.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'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.