A shinytest script in testthat

Posted on November 23, 2019 by Stéphane Laurent
Tags: shiny, R

The shiny app

Here is a simple shiny app:

It allows to set the breaks of the y-axis of the graph:

Unit test

Say we want to test whether the app correctly sets the axis breaks.

When you have a ggplot, you can get the y-axis breaks as follows:

With this piece of code of the app:

we export ggg$layout$panel_params[[1L]].

Assume our package is named shinyFromToBy and the shiny app is saved in file app.R in the inst/shinyApp folder. Then, here is our unit test (to put in the tests/testthat folder):