All Projects → yonicd → Reactor

yonicd / Reactor

Licence: other
unit testing for shiny reactivity

Programming Languages

r
7636 projects

Labels

Projects that are alternatives of or similar to Reactor

Shiny
Easy interactive web applications with R
Stars: ✭ 4,507 (+10143.18%)
Mutual labels:  shiny
Highcharter
R wrapper for highcharts
Stars: ✭ 583 (+1225%)
Mutual labels:  shiny
Datofutbol
Dato Fútbol repository
Stars: ✭ 23 (-47.73%)
Mutual labels:  shiny
Timevis
📅 Create interactive timeline visualizations in R
Stars: ✭ 470 (+968.18%)
Mutual labels:  shiny
Shinywidgets
shinyWidgets : Extend widgets available in shiny
Stars: ✭ 553 (+1156.82%)
Mutual labels:  shiny
Shinydashboard
Shiny Dashboarding framework
Stars: ✭ 718 (+1531.82%)
Mutual labels:  shiny
De
A Programmer's Text Editor
Stars: ✭ 366 (+731.82%)
Mutual labels:  shiny
Shiny Gem
A data analysis web-app written in R Shiny.
Stars: ✭ 15 (-65.91%)
Mutual labels:  shiny
Shinyjs
💡 Easily improve the user experience of your Shiny apps in seconds
Stars: ✭ 566 (+1186.36%)
Mutual labels:  shiny
Shinyappdemo
A demo shiny app inside a package
Stars: ✭ 23 (-47.73%)
Mutual labels:  shiny
Awesome Shiny Extensions
🐝 Awesome R packages that offer extended UI or server components for the R web framework Shiny
Stars: ✭ 521 (+1084.09%)
Mutual labels:  shiny
Golem
A Framework for Building Robust Shiny Apps
Stars: ✭ 530 (+1104.55%)
Mutual labels:  shiny
Mastering Shiny
Mastering Shiny: a book
Stars: ✭ 790 (+1695.45%)
Mutual labels:  shiny
Dt
R Interface to the jQuery Plug-in DataTables
Stars: ✭ 451 (+925%)
Mutual labels:  shiny
Aisvms vis
AIS visualization from an interactive R and Shiny based web app using Material Design from Google.
Stars: ✭ 8 (-81.82%)
Mutual labels:  shiny
Regexplain
🔍 An RStudio addin slash regex utility belt
Stars: ✭ 413 (+838.64%)
Mutual labels:  shiny
Shiny
Iridescent Effect View (inspired by Apple Pay Cash) ✨
Stars: ✭ 707 (+1506.82%)
Mutual labels:  shiny
Sig Bio Shiny
A standalone interactive application for detecting biological significance on a set of genes
Stars: ✭ 34 (-22.73%)
Mutual labels:  shiny
Oak
A pure Go game engine
Stars: ✭ 847 (+1825%)
Mutual labels:  shiny
Ctmmweb
Web app for analyzing animal tracking data, built upon ctmm R package
Stars: ✭ 22 (-50%)
Mutual labels:  shiny

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
#> reactor:
#>   application: ~
#>   driver: ~

Populating Specifications

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

  • application: Specifications for the background process that will host the application
  • driver: Specifications for the webdriver that will interact with the application in the background process

Reactor comes with functions to help you create these specifications

  • application:
    • set_runapp_args() : Assumes that the application is located in a path on the machine and uses shiny::runApp as the function to launch the application
    • set_golem_args(): Assumes that the application is a golem package and uses the golem logic to launch the application.
  • driver:
    • set_chrome_driver(): Launches RSelenium with a chrome webdriver
    • set_firefox_driver(): Launches RSelenium with a firefox (gecko) webdriver
obj <- obj%>%
  set_runapp_args(
    appDir = system.file('examples/good_app.R',package = 'reactor')
  )%>%
  set_chrome_driver()
#> Adding runApp Settings
#> Adding chrome Settings
reactor object
reactor:
  application:
    runApp:
      test_port: 41896
      test_path: /var/folders/kx/t4h_mm1910sb7vhm_gnfnx2c0000gn/T//Rtmp2f3Exn
      test_ip: 127.0.0.1
      appDir: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/reactor/examples/good_app.R
  driver:
    chrome:
      test_path: /var/folders/kx/t4h_mm1910sb7vhm_gnfnx2c0000gn/T//Rtmp2f3Exn
      verbose: no
      port: 11136
      opts:
        args:
        - --headless
        - --disable-gpu
        - --window-size=1280,800
        prefs:
          profile.default_content_settings.popups: 0
          download.prompt_for_download: no
          download.directory_upgrade: yes
          safebrowsing.enabled: yes
          download.default_directory: /var/folders/kx/t4h_mm1910sb7vhm_gnfnx2c0000gn/T//Rtmp2f3Exn

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

obj <- obj%>%
  set_chrome_driver(
     opts = chrome_options(headless = FALSE)
  )
#> Updating chrome Settings
reactor object
reactor:
  application:
    runApp:
      test_port: 41896
      test_path: /var/folders/kx/t4h_mm1910sb7vhm_gnfnx2c0000gn/T//Rtmp2f3Exn
      test_ip: 127.0.0.1
      appDir: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/reactor/examples/good_app.R
  driver:
    chrome:
      test_path: /var/folders/kx/t4h_mm1910sb7vhm_gnfnx2c0000gn/T//Rtmp2f3Exn
      verbose: no
      port: 14336
      opts:
        args:
        - --disable-gpu
        - --window-size=1280,800
        prefs:
          profile.default_content_settings.popups: 0
          download.prompt_for_download: no
          download.directory_upgrade: yes
          safebrowsing.enabled: yes
          download.default_directory: /var/folders/kx/t4h_mm1910sb7vhm_gnfnx2c0000gn/T//Rtmp2f3Exn

Starting Reactor

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

obj%>%
  start_reactor()

Interacting with the application

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

  • set_id_value():
    • expects an input id and the new value
    • returns back the reactor object
obj%>%
  set_id_value('n',500)

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

Inject:

  • Inputs
    • set_id_value(): Sets a value for a shiny input object by id
  • JavaScript
    • execute(): Executes a JavaScript call

Query:

  • Inputs
    • query_input_names(): Returns names of the shiny input ids
    • query_input_id(): Returns current values of a shiny input by id
  • Outputs
    • query_output_names(): Returns names of the shiny output ids
    • query_output_id(): Returns current values of a shiny output by id
  • JavaScript
    • query(): Returns a value from JavaScript call

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()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].