Interactivity in Production

Fd59f90efdaa9dea8f7d9c2f0c930a2b?s=47 kellobri
October 02, 2019

Interactivity in Production

RStudio Webinar

Fd59f90efdaa9dea8f7d9c2f0c930a2b?s=128

kellobri

October 02, 2019
Tweet

Transcript

  1. Interactivity in Production Kelly O’Briant Solutions Engineering

  2. Recap Production Means Different Things to Different People RStudio Connect

    Publishing Platform for communicating impactful data science work R Markdown is a tool for creating computational documents - can contain interactive elements Interactivity Spectrum
  3. None
  4. None
  5. The Case for Starting with Shiny Local Development EDA, Prototyping,

    Iteration • Shiny development starts innocently • Natural choice for tool-building projects in R • Quickly escalates when you want to give access to someone else
  6. A “Starting with Shiny” Simile The “Hour-Long-Talk” of Data Products

    - Rambling, Cluttered - Parts that work well - Parts that work not-so well Local Development EDA, Prototyping, Iteration
  7. A “Starting with Shiny” Simile The “Hour-Long-Talk” of Data Products

    - Rambling, Cluttered - Parts that work well - Parts that work not-so well Local Development EDA, Prototyping, Iteration The “Lightning-Talk” of Data Products - Targeted - Elegant - Streamlined - Optimized Production Development
  8. Agenda - Interactivity in Production • Recap & Intro: The

    Case for Starting with Shiny • Kelly’s Shiny in Production “Most Important Thing” • Joe Cheng’s “Most Important Thing” • An example: CRAN Logs - Trending Packages App ◦ Joe’s Performance Workflow ◦ Refactoring for Production ◦ Evaluating Impact ◦ Reconsidering the Hierarchy of Interactivity
  9. ADVOCATE FOR A SANDBOX PUBLISHING ENVIRONMENT Kelly’s Shiny in Production

    “Most Important Thing” This!
  10. If you only have one server - Even this can

    work Staging Environment Production Environment solutions.rstudio.com | community.rstudio.com R Admins
  11. Joe’s Shiny in Production “Most Important Thing” RStudio Tools and

    Packages to Support Shiny in Production: - shinytest - Automated UI testing for Shiny - shinyloadtest - load testing for shiny - profvis - Profiler for R code - plot caching - dramatically speed up repeated techniques - async - last resort technique for dealing with slow operations resources.rstudio.com/webinars
  12. Joe’s Shiny in Production “Most Important Thing” RStudio Tools and

    Packages to Support Shiny in Production: - shinytest - Automated UI testing for Shiny - shinyloadtest - load testing for shiny - profvis - Profiler for R code - plot caching - dramatically speed up repeated techniques - async - last resort technique for dealing with slow operations resources.rstudio.com/webinars
  13. Turn a Prototype into a Production Application Performance Workflow 1.

    Use shinyloadtest to see if app is fast enough 2. If not, use profvis to see what’s making it slow 3. Optimize a. Move work out of shiny (very often) b. Make code faster (very often) c. Use caching (sometimes) d. Use async (occasionally) 4. Repeat! CRAN Whales App is so slow • We didn’t know until shinyloadtest • Profile - the code: why is it so slow? • ETL Process - Moving work out of Shiny
  14. RStudio CRAN Logs - Trending Packages Explorer 1. Calls the

    cranlogs API /trending endpoint to get the top 10 trending packages 2. Makes 10 more calls to the cranlogs API to retrieve download counts for each package 3. Drops that data into DT 4. Uses rvest magic to scrape metadata about each package Visit the cranlogs API project on GitHub: r-hub/cranlogs.app
  15. RStudio CRAN Logs - Trending Packages Explorer Works great in

    my local development environment! Works okay on my RStudio Connect staging server… Is it fast enough to support the number of users I expect? Activate the Performance Workflow! Visit the cranlogs API project on GitHub: r-hub/cranlogs.app
  16. RStudio CRAN Logs - Trending Packages Explorer Performance Workflow 1.

    Use shinyloadtest to see if app is fast enough 2. If not, use profvis to see what’s making it slow 3. Optimize a. Move work out of shiny (very often) b. Make code faster (very often) c. Use caching (sometimes) d. Use async (occasionally) 4. Repeat! • Don’t do work while the user is waiting • Don’t do the same work for every user
  17. Production Development: Move Work Out of Shiny Don’t do work

    while the user is waiting. Eleven API requests to create the “Trending R Packages” table. Don’t do the same work for every user. Wasteful! Two rvest function calls performed for every row selection.
  18. Pre-generate the Data, Publish it with the App?

  19. Division of Labor: R Markdown Output Files

  20. Update Shiny with an R Markdown ETL Process

  21. Production Development

  22. Goal: Make an impact at your organization “It doesn’t matter

    how great your analysis is unless you can explain it to others: You need to communicate your results.”
  23. RStudio Connect Instrumentation API RStudio Connect records different types of

    user activity for different types of content. 1. Shiny applications - records information about each visit and the length of that visit. 2. Static and rendered content - records information about each visit. github.com/sol-eng/connect-usage Code examples showing how to access the instrumentation data are in the User Activity recipes within the RStudio Connect API Cookbook.
  24. Monitor Content with Instrumentation Data This app is popular! Scale

    it! or... This app isn’t getting visited… now what? • Set a Daily Visit goal • Set a Session Duration goal Send an alert when the app isn’t making the desired impact
  25. Evaluate A Low-Traffic Application Awesome Alternatives - Sometimes honing a

    Shiny Application means taking a different approach Sacrifice Shiny Runtime to Achieve: • Parameterized R Markdown • Scheduled email report delivery • Plumber REST API Custom Email Alert Message from Instrumentation Dashboard
  26. Hierarchy of Interactivity + Shiny in Production

  27. Production Building Blocks Code Profiling Version Control Testing Deployment/Release Access/Security

    Performance Tuning bit.ly/shiny-prod-book RStudio Conf Keynote 2019