$30 off During Our Annual Pro Sale. View Details »

Interactivity in Production

kellobri
October 02, 2019

Interactivity in Production

RStudio Webinar

kellobri

October 02, 2019
Tweet

More Decks by kellobri

Other Decks in Technology

Transcript

  1. Interactivity in Production
    Kelly O’Briant
    Solutions Engineering

    View Slide

  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

    View Slide

  3. View Slide

  4. View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  9. ADVOCATE FOR A
    SANDBOX PUBLISHING
    ENVIRONMENT
    Kelly’s Shiny in Production “Most Important Thing”
    This!

    View Slide

  10. If you only have one server - Even this can work
    Staging Environment
    Production Environment
    solutions.rstudio.com | community.rstudio.com R Admins

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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.

    View Slide

  18. Pre-generate the Data, Publish it with the App?

    View Slide

  19. Division of Labor: R Markdown Output Files

    View Slide

  20. Update Shiny with an R Markdown ETL Process

    View Slide

  21. Production
    Development

    View Slide

  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.”

    View Slide

  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.

    View Slide

  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

    View Slide

  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

    View Slide

  26. Hierarchy of Interactivity + Shiny in Production

    View Slide

  27. Production Building Blocks
    Code Profiling
    Version Control
    Testing
    Deployment/Release
    Access/Security
    Performance Tuning
    bit.ly/shiny-prod-book
    RStudio Conf Keynote 2019

    View Slide