shinytest2
shinytest2 provides automated testing for Shiny applications using a headless Chrome browser. It integrates with the testthat framework to help developers catch regressions when adding features, fixing bugs, or upgrading dependencies.
The package uses chromote to render applications in headless Chrome, enabling live preview, modern JavaScript/CSS support, and better debugging tools. You can record user interactions as test code and extend them to verify specific application behaviors, making testing more consistent and scalable than manual approaches.
Contributors#
Resources featuring shinytest2#
Mark Wang - Using GitHub Copilot in R Shiny Development
Generative AI tools, like the GitHub Copilot, are revolutionizing software development, by automating routine tasks and boosting programmers’ productivity. R Shiny development is uniquely positioned to benefit from GitHub Copilot. Copilot can accelerate the process by automating front-end tasks, especially those involving HTML and JavaScript, as well as testing and documentation, thus letting R Shiny developers focus more on the value-added aspects of data science and statistics.
The basic workflow of using GitHub copilot in R Shiny development has three parts: prompt, context, and iteration. Three types of prompts: command, question, and lead-in, all have strong use cases in R development. Specific prompts create more helpful results as compared to vague ones, and Copilot can help add more specificity to your prompts when you are not familiar with the domain topic. The most important source of context for Copilot is typically your codebase, which should be well-organized and open in your IDE. Additionally, knowledge on the internet, as well as simple and concrete examples, can also be valuable contexts. However, sensitive personal information in your context can stop Copilot from generating appropriate responses. Iteration is modifying and enriching your prompt and context to improve the quality of Copilot’s responses. Function and module documentation is a valuable step of iteration. As R Shiny is often used with fast-hanging data, Copilot serves as a powerful tool in the iteration from static to dynamic app testing in the shinytest2 framework.
As we iterate over our prompt and context to generate better responses from Copilot, it is worthwhile to build an internal knowledge base in the form of prompt dictionaries. A Copilot knowledge base can include information specific to your organization that can be reused across projects, such as security and compliance conventions, code and documentation standards, and employment process and environment.
Talk by Mark Wang
Slides: https://1drv.ms/b/c/fd70c8a06be32527/ER8WuxYEw_NKksTI6t5wCDgBrO9slTr0HaumYp1eg2xYYA?e=KwQSfb GitHub Repo: https://github.com/ZIBOWANGKANGYU/posit_2024_prez/tree/master/presentation
Barret Schloerke | {shinytest2}: Unit testing for Shiny applications | RStudio (2022)
Manually testing Shiny applications is often laborious, inconsistent, and doesn’t scale well. Whether you are developing new features, fixing bug(s), or simply upgrading dependencies, it is critical to know when regressions are introduced. The new {shinytest2} R package provides a toolkit for unit testing Shiny apps and seamlessly integrates with {testthat}. Under the hood, it uses the new {chromote} R package to render apps in a headless Chrome browser with features such as live preview and built in debugging tools. In this talk, you’ll learn how to test Shiny apps by simply recording your actions as code and extending it to test more particular aspects of your app, resulting in fewer bugs and more confidence in future development.
Talk materials are available at https://bit.ly/shinytest2-conf22
Session: I like big apps: Shiny apps that scale

Getting Started with {shinytest2} Part 2 || Exporting values || RStudio
00:00 Introduction 00:29 Exporting reactives 03:28 Using exportTestValues()
Part 1 - Getting started: https://youtu.be/SS1Na3c8lhk Part 3 - Using shiny.testmode: https://youtu.be/xDxa_mDwN04
Manually testing Shiny applications is often laborious, inconsistent, and doesn’t scale well. Whether you are developing new features, fixing bug(s), or simply upgrading dependencies on a serious app where mistakes have real consequences, it is critical to know when regressions are introduced. shinytest2 provides a streamlined toolkit for unit testing Shiny applications and seamlessly integrates with the popular testthat framework for unit testing R code.
shinytest2 uses chromote to render applications in a headless Chrome browser. chromote allows for a live preview, better debugging tools, and/or simply using modern JavaScript/CSS.
By simply recording your actions as code and extending them to test the more particular aspects of your application, it will result in fewer bugs and more confidence in future Shiny application development.
Read up on shinytest2 here: https://rstudio.github.io/shinytest2/
Learn more about Shiny here: https://shiny.rstudio.com/
Got questions? The RStudio Community site is a great place to get assistance: https://community.rstudio.com/
Content: Barret Schloerke (@schloerke) Motion design and editing: Jesse Mostipak (@kierisi)
Theme song: Brad PKL by Blue Dot Sessions (https://app.sessions.blue/browse/track/113507 )

Getting Started with {shinytest2} Part 3 || Using shiny.testmode in {shinytest2} || RStudio
00:00 Introduction 00:15 Testing production apps
Part 1 - Getting started: https://youtu.be/SS1Na3c8lhk Part 2 - Exporting values: https://youtu.be/7KLv6HdIxvU
Manually testing Shiny applications is often laborious, inconsistent, and doesn’t scale well. Whether you are developing new features, fixing bug(s), or simply upgrading dependencies on a serious app where mistakes have real consequences, it is critical to know when regressions are introduced. shinytest2 provides a streamlined toolkit for unit testing Shiny applications and seamlessly integrates with the popular testthat framework for unit testing R code.
shinytest2 uses chromote to render applications in a headless Chrome browser. chromote allows for a live preview, better debugging tools, and/or simply using modern JavaScript/CSS.
By simply recording your actions as code and extending them to test the more particular aspects of your application, it will result in fewer bugs and more confidence in future Shiny application development.
Read up on shinytest2 here: https://rstudio.github.io/shinytest2/
Learn more about Shiny here: https://shiny.rstudio.com/
Got questions? The RStudio Community site is a great place to get assistance: https://community.rstudio.com/
Content: Barret Schloerke (@schloerke) Motion design and editing: Jesse Mostipak (@kierisi)
Theme song: Brad PKL by Blue Dot Sessions (https://app.sessions.blue/browse/track/113507 )

Getting Started with {shinytest2} Part I || Example + basics || RStudio
00:00 Introduction 00:48 Overview of the demo Shiny app 03:00 Running record_test() 04:44 Results from record_test() 07:18 A note on .png files created during testing 08:52 Debugging with shinytest2 09:32 Using app$view() to open a visual representation of a headless browser
Part 2 - Exporting values: https://youtu.be/7KLv6HdIxvU Part 3 - Using shiny.testmode: https://youtu.be/xDxa_mDwN04
Manually testing Shiny applications is often laborious, inconsistent, and doesn’t scale well. Whether you are developing new features, fixing bug(s), or simply upgrading dependencies on a serious app where mistakes have real consequences, it is critical to know when regressions are introduced. shinytest2 provides a streamlined toolkit for unit testing Shiny applications and seamlessly integrates with the popular testthat framework for unit testing R code.
shinytest2 uses chromote to render applications in a headless Chrome browser. chromote allows for a live preview, better debugging tools, and/or simply using modern JavaScript/CSS.
By simply recording your actions as code and extending them to test the more particular aspects of your application, it will result in fewer bugs and more confidence in future Shiny application development.
Read up on shinytest2 here: https://rstudio.github.io/shinytest2/
Learn more about Shiny here: https://shiny.rstudio.com/
Got questions? The RStudio Community site is a great place to get assistance: https://community.rstudio.com/
Content: Barret Schloerke (@schloerke) Motion design and editing: Jesse Mostipak (@kierisi)
Theme song: Brad PKL by Blue Dot Sessions (https://app.sessions.blue/browse/track/113507 )

Veerle van Leemput | Analytic Health | Optimizing Shiny for enterprise-grade apps
Can you use Shiny in production? A: Yes, you definitely can.
Link to slides: https://github.com/RStudioEnterpriseMeetup/Presentations/blob/main/VeerlevanLeemput-OptimizingShiny-20220525.pdf
Packages mentioned: ⬢ shiny: https://shiny.rstudio.com/ ⬢ pins: https://pins.rstudio.com/ ⬢ plumber: https://www.rplumber.io/ ⬢ blastula: https://github.com/rstudio/blastula ⬢ callR: https://github.com/r-lib/callr ⬢ shinyloadtest: https://rstudio.github.io/shinyloadtest/ ⬢ shinycannon: https://github.com/rstudio/shinycannon ⬢ shinytest2: https://rstudio.github.io/shinytest2/ ⬢ feather: https://github.com/wesm/feather ⬢ shinipsum: https://github.com/ThinkR-open/shinipsum ⬢ bs4Dash: https://rinterface.github.io/bs4Dash/index.html
Timestamps: 2:44 - Start of presentation 5:41 - What qualifies as an enterprise-grade app? 10:46 - UI first / user experience / prototyping 13:20 - Separating code into separate scripts and creating code that’s easy to test 17:15 - Golem 19:28 - Functionize your code 20:50 - Rhino package, framework for developing enterprise-grade apps at speed 22:33 - Infrastructure, how do you bring this to your users? (lots of ways to do this. They do this with R, pins, plumber, rmd, blastula, and Posit Connect on Azure) 31:17 - Optimizing Shiny (process configuration, cache, callR, API, feather) 47:35 - Testing your app (shinyloadtest and shinycannon) 50:23 - Testing for outcomes (shinytest2) 52:15 - Monitor app performance & usage (blastula, shinycannon, usage metrics with Shiny app)
Questions: 57:38 - What’s the benefit of using pins rather than pulling the data from your database? 59:30 - Are there package license considerations you had to think about when monetizing shiny applications? 1:00:45 - Do you use promises to scale the application? (they use CallR) 1:01:49 - For beginners, golem or rhino? 1:02:50 - The myth is that only Python can be used for production apps, what made you choose to use R? 1:05:12 - Is feather strictly better than using JSON? 1:06:38 - Where do you see the line between BI (business intelligence) and Shiny for your applications? 1:08:36 - Any tips for enterprise-grade UI development? Making beautiful apps (bs4Dash app) 1:10:25 - Have you found an upper limit for users? 1:12:19 - Any tips for more dynamic data? (optimizing database helps here) 1:13:50 - Where do you install shinycannon? (on our development Linux server) 1:15:00 - Can you share other resources or examples of code? (Slides here with resources: https://github.com/RStudioEnterpriseMeetup/Presentations/blob/main/VeerlevanLeemput-OptimizingShiny-20220525.pdf )
For upcoming events: rstd.io/community-events-calendar Info on Posit Connect: https://www.rstudio.com/products/connect/ To chat with Posit: rstd.io/chat-with-rstudio