Skip to content

examples to implement asynchronous programming in Shiny ✨

License

Notifications You must be signed in to change notification settings

glenn-christmas/async_shiny

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asynchronous programming in Shiny

This repo contains examples to implement asynchronous programming in Shiny ✨

Async programming can sound very daunting but by providing specific Shiny examples the aim is to speed up the learning curve.

About asynchronous programming

Asynchronous programming allows for the execution of multiple tasks concurrently, improving the performance and responsiveness of Shiny applications. Traditional synchronous programming executes tasks sequentially, which can result in slower response times and blocked resources. By default, a Shiny applications runs on a single-threaded synchronous R session.

Asynchronous programming in Shiny can be achieved through various packages that provide mechanisms for running code concurrently, such as promises, callr, coro, mirai and crew. These packages allow developers to write more efficient and responsive code.

Examples

  • promises: two examples demonstrating cross-session asynchronicity using promises and future. One example demonstrations inner-session asynchronicity as well by making use of a reactiveVal() structure. This follows the examples in Engineering Production-Grade Shiny Apps.
  • callr: two examples that show how to spin up background R processes. The basic example runs a long computation in the background, and the markdown example knits a markdown document in the background.
  • coro: one example that demonstrates how to program concurrently using the async() function from coro. In this example, we also use promises and we demonstrate how promise_all() works to handle multiple promises at the same time.
  • mirai: one example that will walk you through the minimalist package called mirai (which means future in Japanese). mirai provides a simple interface to efficiently schedule tasks. You can implement mirai in a Shiny app by using mirai.promises instead of a promise. For more extensive documentation check out mirai on GitHub.
  • crew: on top of mirai, there's a package called crew that helps you to manage and control workers. The interface is pretty neat and intuitive. There's a lot of functionality, which includes the option to specify remote workers. In this folder there are two examples: one that demonstrates how to send a single task to a worker, and one that demonstrates how to send multiple tasks to multiple workers. For more info see crew on GitHub.
  • the shiny_gatherings folder contains 3 Shiny apps: 1 base app, 1 app turning the base into an async app with crew, and 1 app turning the base app into an async app with callr. There's also a video on YouTube where I go over these examples 🙌.

Future plans

The plan is to add more examples and tutorials on how to implement asynchronous programming in Shiny. Keep an eye on this repository for updates.

Contributors 📣

Do you want to add examples to this repo? That's awesome 👏 . I'm welcoming all support!

Watch "Mastering Asynchronous Programming in Shiny"

You can watch the keynote talk on the ShinyConf2023 back on the Appsilon YouTube channel 🎥

The slides of the presentation are also available.

About

examples to implement asynchronous programming in Shiny ✨

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 100.0%