Supporting the R Community - Be The Best With Shinytest · 2018. 4. 10. · Developer •design...
Transcript of Supporting the R Community - Be The Best With Shinytest · 2018. 4. 10. · Developer •design...
Be The Best With Shinytest
Web Development
Shiny
Testing
Shinytest
Web Development
Two Roles for Data Scientists
• Analyst • Developer
Analyst
• design and build workflow – asking a question– gathering data– generating insight– guiding decision making
• investigate impact of assumptions and determine value of workflow
• use existing tools and develop new tools
Developer
• design algorithms that are independent of data
• identify desirable behaviours of algorithm, recognise edge cases
• abstract algorithm into conceptual units• create and document code• test units to demonstrate expected
behaviour• maintain code as software dependencies
and needs of business change
More Roles
• Analyst • Web Developer
• Developer
Web Developer
• wireframe/layout a web application• write HTML and CSS• turn a design into a working website• add interactivity to a website with JavaScript or
jQuery• write an application in an object-oriented
programming language (Ruby, Python or PHP)• work with a version control system like Git• manage a domain’s DNS settings• deploy a website to a website hosthttps://teamtreehouse.com/community/the-list-of-minimum-skills-you-need-to-master-to-call-yourself-a-web-developer
Shiny
Shiny
• Massively popular web application framework
• Winston Chang, Joe Cheng, ...
Web Developer
• wireframe/layout a web application• write HTML and CSS• turn a design into a working website• add interactivity to a website with JavaScript or
jQuery• write an application in an object-oriented
programming language (Ruby, Python or PHP)• work with a version control system like Git• manage a domain’s DNS settings• deploy a website to a website host
Web Developer
• shiny• shiny• shiny• shiny• write an application in R
• work with a version control system like Git• manage a domain’s DNS settings• deploy a website to a website host
Soon Every R Conference Presentation will be about Shiny
Testing
Testing
• Define expected output• Compare object with expected• Fast and fun
Testing Vital for Effective Development• Find defects• Manage impact of new features• Manage impact of changes to
dependencies
Testing Essential for Validation
• Demonstrate features are present• Qualify operation of installed application
Quick to Check Tests Pass
> library(testthat)> test_package("mangoNCA") test AUCInfObs: ......... test AUCInfPred: ......... test AUCLast: ....................test AUCLin: .............. test AUCLog: ................
Clear Failures
Failed --------------------------
1. Failure: check selectPoints(@test_selectPoints.R#25) --------
test3$lamznpt not equal to 4.
1/1 mismatches [1]
3 - 4 == -1
Shinytest
Shinytest
• R-based testing framework for Shiny• Gabor Csardi
Shinytest
Shinytest
• Snapshot based testing• Record– script of test actions– app state
• Replay and compare
Not yet on CRAN
library(devtools)
install_github("rstudio/webdriver")
install_github("rstudio/shinytest")
Create New Test
• Start recording• Interact with Shiny app• Take snapshots
Start Recording
> recordTest("Quiz")
Interact with Shiny app
• Click through app
Take Snapshot
• Recorder app
• Snapshot and continue or exit
Script of Test Actions
app <- ShinyDriver$new("..")
app$snapshotInit("mytest")
app$setInputs(
q1 = "reg = read.csv('Temp/reg.csv')")
app$setInputs(button = "click")
app$snapshot()
Test Directory Created in App
• Test script• App data• Screenshot
Running Tests
• Test driver process• Shiny server process• Web browser client process
Quick to Check Tests Pass
testApp("Quiz", "mytest")
Running mytest.R
====== Comparing mytest ======
Clear Failures
testApp("Quiz", "mytest")Running mytest.R====== Comparing mytest ======Differences detected between
mytest-current/ and mytest-expected/:
Name Status 001.json != Files differ001.png != Files differ
Shinytest
• Automated testing framework for Shiny apps
• All necessary tools installable from R• Outputs can be used with other test
frameworks• Best development practice makes the
best web apps
References
• https://github.com/rstudio/shinytest• https://rstudio.github.io/shinytest/• https://www.mango-
solutions.com/datascience/products/valid-r/