Workshop · 122 min · Available now · Production & Deployment

The Pit Stop

Keep a shared Shiny app responsive for everyone while one user's long query runs.

An agent can write the workflow. This workshop is about what happens at three in the morning when it fails.

$149 Buy now Buy once, watch any time. A person answers if it is the wrong one for you.
What you learn

The skills, and the artifact you leave with.

  • Spot the single-threaded bottleneck in a Shiny session and measure it
  • Move slow work onto a mirai daemon with ExtendedTask and bind it to a button
  • Show a running state, invalidate stale results, and cancel cleanly
  • Keep data access in one module so the fix lives in one place
You leave with

A working app where a nine-second query no longer freezes the staff, with the pattern isolated so you can apply it to your own.

Why it matters now

Every shared analytics app hits this the first time two people use it at once; the fix is small and almost nobody has seen it done.

10 lessons, 2 h 02 min
  1. 01The Plan and the F1 Hub App7:09
  2. 02Why Blocking Hurts: 22 Second Waits11:03
  3. 03Sync Template and Blocking Demo15:32
  4. 04Async, Concurrent, Parallel, Multi-core Terms5:33
  5. 05History: Promises, Callr, Crew, mirai8:30
  6. 06ExtendedTask and mirai Daemons Setup12:10
  7. 07Async Template and Parallel Tasks18:59
  8. 08Speeding Up With mirai Map6:49
  9. 09Rate Limits, Timeouts and Error Handling16:05
  10. 10Common Mistakes, Debugging, Final Hub20:26
Try it

The freeze, and the fix, from the workshop's own lessons.

Both demos replay timings measured by running the workshop's code. Nothing is sent anywhere and nothing loads from another site.

One R process, three users

Press Load race weekend for any of the three users and watch the clocks. Then switch to six workers and do it again.

Interactive timeline not loading? One load of the hub takes 21.2 s. With one R process, three users who click 3 s apart get their data 21.2 s, 39.5 s and 57.7 s after they click, and every clock freezes for 63.7 s. With ExtendedTask and six workers, each gets their data 21.2 s after their own click, and no clock freezes.

Fan out the lap times

Move the worker slider from 1 to 8 and compare the two versions of the workshop's code.

Interactive chart not loading? Measured with six workers: 7.1 s with lapply on one worker (03_parallel.R), 5.0 s with mirai_map() (04_mirai_map.R), 2.1 s saved. With one worker they take 21.2 s and 21.3 s: mirai_map() needs free workers.

From the code

The code you work in, as it is in the workshop files.

Start the workers once, when the app starts, and give each one the fetch functionstemplates/02_one_task.R, lines 17 to 22
# Start background R processes. A worker is a fresh R session, so load the
# fetch functions on each one.
# Each running app keeps 6 extra R processes: stop it before starting the next.
daemons(6)
everywhere(source(here::here("data", "pitwall", "fetch.R")))
onStop(function() daemons(0))
One ExtendedTask: the fetch runs on a worker, and the button is bound to ittemplates/02_one_task.R, lines 97 to 107
  # fetch_hub() is defined in this script, not in fetch.R, so the worker
  # doesn't have it. Send it along with the call in .args.
  hub_task <- ExtendedTask$new(function() {
    mirai(fetch_hub(), .args = list(fetch_hub = fetch_hub))
  }) |>
    bind_task_button("go")

  observe({
    hub_task$invoke()
  }) |>
    bindEvent(input$go)
One call per driver, spread over the workerstemplates/04_mirai_map.R, lines 94 to 98
  # One fetch_laps() call per driver, spread over the workers. .args are
  # passed to every call.
  laps_task <- ExtendedTask$new(function(key, drivers) {
    mirai_map(drivers, fetch_laps, .args = list(session_key = key))
  })
A timeout on a task, so a slow API fails one panel and not the apptemplates/05_robust.R, lines 111 to 114
  # .timeout is in milliseconds. When it runs out, the task fails.
  standings_task <- ExtendedTask$new(function(timeout) {
    mirai(fetch_standings(), .timeout = timeout)
  })
The curriculum

10 lessons, 2 h 02 min.

  1. 01The Plan and the F1 Hub AppIntroduces the workshop plan and the F1 race weekend hub the group will build for the US Grand Prix in Austin. It lists the seven panels and the APIs behind them (Jolpica, OpenF1, Open-Meteo, Wikipedia), and shows the polished five second target app.7:09
  2. 02Why Blocking Hurts: 22 Second WaitsExplains why a 21.2 s sequential load hurts, using Nielsen's 0.1, 1 and 10 second limits. Shows that R does one thing at a time and defines intrasession and intersession blocking on a shared R process.11:03
  3. 03Sync Template and Blocking DemoWalks through the first sync template and the fetch and display helper scripts, with deliberate delays and caching. Runs the app to show the frozen clock and the 21.2 s blocking wait.15:32
  4. 04Async, Concurrent, Parallel, Multi-core TermsClarifies the vocabulary of sequential, asynchronous, concurrent, parallel and multi-core using a barista and coffee shop metaphor. Notes that R can do all of these with the help of extra packages.5:33
  5. 05History: Promises, Callr, Crew, miraiGives a history of async in Shiny, from promises and future through callr and crew to mirai and ExtendedTask in Shiny 1.8.1. Introduces workers, the main session, task statuses and the upcoming shinyAsync wrapper.8:30
  6. 06ExtendedTask and mirai Daemons SetupShows the ExtendedTask structure with invoke, status and result, and the input task button bound with bind_task_button. Covers setting up mirai daemons, everywhere, onStop cleanup, why workers start as fresh R sessions and that invoking again queues rather than cancels.12:10
  7. 07Async Template and Parallel TasksConverts the sync app into the async template: one big task is non-blocking but still takes 21.2 s. She then splits it into one task per panel, chains the stints and laps tasks on the race task status, and resets the task button manually once all tasks are done, bringing the time to 7.1 s.18:59
  8. 08Speeding Up With mirai MapSpeeds up the slowest task, the lap times panel, by replacing mirai with mirai_map to fan out the 10 per driver calls across workers. This cuts the load from 7.1 s to 5.0 s and motivates iterating on the slowest task.6:49
  9. 09Rate Limits, Timeouts and Error HandlingCovers OpenF1 rate limits and 429 errors, retrying with req_retry and caching historical data. Builds robustness with per task .timeout, status badges and validate messages, demoed with a simulated Wikipedia outage in the fifth template.16:05
  10. 10Common Mistakes, Debugging, Final HubReviews common mistakes such as slow work in observers, missing worker context, reading inputs inside tasks, chaining on result and forgetting onStop. Gives debugging tips with sync = TRUE and output = TRUE, shows the full styled hub app with a one mechanic versus pit crew switch and telemetry.20:26
Free preview

Watch lesson 1, free.

Lesson 1: The Plan and the F1 Hub App 7:09

From the recording

Three clips, straight from the workshop.

Async Is Not Parallel 1:13

The Number One Async Mistake 0:33

Total Time Is the Slowest Task 0:33

The problem

A shared Shiny app freezes for every user while one user's long query runs, because a Shiny session is single-threaded and the server waits with it.

Three decisions it teaches
  1. Where the slow work goes: an ExtendedTask backed by a mirai daemon, off the session's thread
  2. What the user sees while it runs, and when a stale result is thrown away
  3. Where the data access lives, so the fix is in one module and not scattered through the app

The artifact. A working app where a nine-second query no longer freezes the staff, with the pattern isolated so you can apply it to your own.

10 lessons, 2 h 02 min
  1. 01The Plan and the F1 Hub App7:09
  2. 02Why Blocking Hurts: 22 Second Waits11:03
  3. 03Sync Template and Blocking Demo15:32
  4. 04Async, Concurrent, Parallel, Multi-core Terms5:33
  5. 05History: Promises, Callr, Crew, mirai8:30
  6. 06ExtendedTask and mirai Daemons Setup12:10
  7. 07Async Template and Parallel Tasks18:59
  8. 08Speeding Up With mirai Map6:49
  9. 09Rate Limits, Timeouts and Error Handling16:05
  10. 10Common Mistakes, Debugging, Final Hub20:26
What you get

Everything that exists for this session, and nothing that does not.

  • The recording122 minutes, yours to keep
Play with the data

Run the code, in your browser.

The chart on this page, drawn by code you can edit. R runs on webR and Python on Pyodide; nothing loads until you press Run, and nothing you type leaves the page.

This chart is the code's result. Run recomputes it in your browser.
Run differential game by game (bars), its rolling mean (line) and a band of one rolling sd.

Edit me: Move the window, or change the metric to runs_scored and run again.

Data: Season game log (game_log.csv). Simulated for practice by AthlyticZ (agents/sim_data.py, seed 20261109). License CC BY 4.0.

The code runs in your browser on webR or Pyodide; nothing you type leaves the page.

Veerle Eeftink-van Leemput
Your instructor Veerle Eeftink-van Leemput

Director @ Hypebright B.V.

Teaches the method the way it is used in the role above. The team page lists everything they teach here.

Also teaches ProductioniZing Shiny Applications, Mobile StructureZ, CustomiZing WidgetZ, The No-Look Pass.

Veerle Eeftink-van Leemput is Director at Hypebright B.V. Veerle's work here sits in Production & Deployment and Apps & Dashboards. On AthlyticZ, Veerle teaches The Pit Stop, ProductioniZing Shiny Applications, Mobile StructureZ, CustomiZing WidgetZ, The No-Look Pass and The Farm System.

What is included

What is yours when you buy.

  • The full recording, 122 min
  • Yours to keep: watch it any time

Refunds. If you bought it and it is the wrong one for you, write to michael@athlyticz.com and a person will answer.

Questions

The ones that stop a purchase.

Is this too advanced, or too basic, for me?

Built for someone who already writes code in the session's language and wants the method, not the syntax. If the outcome line at the top reads like something you could use next week, it is pitched right. If it reads like a different job, start with the courses on /browse.

What exactly do I get, and for how long?

The full recording, yours to keep: buy once, watch any time. Masterclass subscribers get every live session for a year and can watch every recorded session for as long as they are a member. Everyone else can buy a recording on its own.

Do I need to install anything?

No. The recording plays in the browser.

What if it is not for me?

Twenty minutes on a call before you buy costs nothing, and the call is the fastest way to tell. If you bought it and it is the wrong one for you, email michael@athlyticz.com and a person will answer.

Want more?

Ten live hours of end-to-end project work every month.

The Masterclass is all of it, live and recorded, for $1,899 a year, or $199 a month. Paid by the month, it renews monthly at $199, cancel any time by replying to your receipt.

This session $149

The Pit Stop. The recording, yours to keep.

Buy now
The Masterclass $1,899 a year, or $199 a month

Every live session this year, and every recording.

Join the Masterclass
Membership $2,999 a year

The whole catalog of courses plus the Masterclass.

Get Membership
$149Buy now