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

[BristolR] Engineering Production-Grade Shiny Apps with {golem}

[BristolR] Engineering Production-Grade Shiny Apps with {golem}

Talk during the online BristolR meetup

Colin Fay

April 27, 2020
Tweet

More Decks by Colin Fay

Other Decks in Programming

Transcript

  1. Engineering Production-Grade Shiny Apps
    with {golem}
    2020-04-27 - BRISTOLR
    Colin Fay - ThinkR
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 1 / 27

    View Slide

  2. $ whoami
    Colin FAY
    Data Scientist & R-Hacker at ThinkR, a french company focused on Data Science & R.
    Hyperactive open source developer.
    http://thinkr.fr
    http://rtask.thinkr.fr
    http://twitter.com/_colinfay
    http://github.com/colinfay
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 2 / 27

    View Slide

  3. ThinkR
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 3 / 27

    View Slide

  4. Data Science engineering, focused on R.
     Training
     Software Engineering
     R in production
     Consulting
    ThinkR
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 4 / 27

    View Slide

  5. Building Shiny Apps
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 5 / 27

    View Slide

  6. Building Proof of Concept
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 6 / 27

    View Slide

  7. But the truth is...
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 7 / 27

    View Slide

  8. But the truth is...
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 7 / 27

    View Slide

  9. But the truth is...
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 7 / 27

    View Slide

  10. Which leads to...
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 8 / 27

    View Slide

  11. Why?
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 9 / 27

    View Slide

  12. Here comes {golem}
     If you have to copy and paste a piece of code more than twice, write a
    function
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 10 / 27

    View Slide

  13. Here comes {golem}
     If you have to copy and paste a piece of code more than twice, write a
    function
     If you have to copy and paste an infrastructure more than twice, write a
    framework
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 10 / 27

    View Slide

  14. Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 11 / 27

    View Slide

  15. Here comes {golem}
    {golem} is an R package that contains a framework for building production-ready
    Shiny Applications.
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 12 / 27

    View Slide

  16. Why using {golem}?
     Automate the boring stuff
    repetitive tasks
     Work with reliable tools
     Gain time developing
     Simplify deployment
     Standardize team work
    About {golem} at ThinkR:
     First built out of internal need,
    today used on a daily basis (I'm the
    #1 {golem} user)
     We needed reliable and
    consistent tooling for deploying to
    our clients' environments
     Build collective intelligence and
    share good practices globally
     Promote R & Shiny in production
    Why {golem}?
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 13 / 27

    View Slide

  17. What's a "prod-ready" software?
     Has meta-data
     Is divided in functions
     Is tested
     Lists requirements
     Is documented
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 14 / 27

    View Slide

  18.  Has meta-data
     Is divided in functions
     Is tested
     Lists requirements
     Is documented
    DESCRIPTION
    R/
    tests/
    NAMESPACE
    man/ & vignettes
    {golem} central philosophy
    Shiny App As a Package
    What's a "prod-ready" Shiny App?
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 15 / 27

    View Slide

  19. And the cool thing...
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 16 / 27

    View Slide

  20. golex
    ├── DESCRIPTION
    ├── NAMESPACE
    ├── R
    │ ├── app_config.R
    │ ├── app_server.R
    │ ├── app_ui.R
    │ └── run_app.R
    ├── dev
    │ ├── 01_start.R
    │ ├── 02_dev.R
    │ ├── 03_deploy.R
    │ └── run_dev.R
    ├── inst
    │ ├── app
    │ │ └── www
    │ │ └── favicon.ico
    │ └── golem-config.yml
    └── man
    └── run_app.Rd
    Standard
    things
    DESCRIPTION, NAMESPACE, man/
    R/

    app_server & app_ui: Shiny UI and
    Server
    run_app: launches your app
    dev/

    0._.*.R: scripted worflows
    golem-config.yml: {config} files
    run_dev.R: relaunches your app while
    developing
    Understanding {golem}
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 17 / 27

    View Slide

  21. Wait...
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 18 / 27

    View Slide

  22. Build
    golem::add_module()
    golem::add_css_file()
    golem::use_external_js_file()
    golem::add_js_handler()
    golem::use_favicon()
    Deploy
    golem::add_rstudioconnect_file()
    golem::add_shinyappsio_file()
    golem::add_shinyserver_file()
    golem::add_dockerfile()
    Automation with {golem}
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 19 / 27

    View Slide

  23. Template files (and where to put them)
    golem::add_module( name = "my_module.R" )
    ✓ File created at R/mod_my_module.R
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 20 / 27

    View Slide

  24. ...
    #' @importFrom shiny NS tagList
    mod_my_module_ui <- function(id){
    ns <- NS(id)
    tagList(
    )
    }
    #' @noRd
    mod_my_module_server <- function(input, output, session){
    ns <- session$ns
    }
    ## To be copied in the UI
    # mod_my_module_ui("my_module_ui_1")
    ## To be copied in the server
    # callModule(mod_my_module_server, "my_module_ui_1")
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 21 / 27

    View Slide

  25. And now
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 22 / 27

    View Slide

  26. What's next?
    All WIP and ideas are currently listed at https://github.com/ThinkR-open/golem/issues
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 23 / 27

    View Slide

  27. What's next?
    Spread the word (and share stickers): tweets, blog posts, talk to your friends and
    family about {golem}
    Open issues when you encounter a bug
    Give feedback about things you might find weird
    Open issue if you have idea / feature requests
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 24 / 27

    View Slide

  28. golemverse.org
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 25 / 27

    View Slide

  29. engineering-shiny.org
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 26 / 27

    View Slide

  30. Online
    [email protected]
    http://twitter.com/_colinfay
    http://twitter.com/thinkr_fr
    https://github.com/ColinFay
    https://thinkr.fr/
    https://rtask.thinkr.fr/
    https://colinfay.me/
    Related projects
    engineering-shiny.org
    {golem}
    {shinipsum}
    {fakir}
    {shinysnippets}
    Thx! Questions?
    Colin Fay
    Colin FAY (@_ColinFay) - https://rtask.thinkr.fr 27 / 27

    View Slide