Repository navigation
run shiny help examples in the console instead of locking up - #17908
Conversation
clicking "run examples" on a help page whose examples launch a blocking app (e.g. shiny::runApp) rendered them inline via the help server, which runs the example on the r event loop and never returns, locking up the session (#17178). detect such examples by parsing the example/demo source and route them to the console via example()/demo() instead, matching the behavior of running example() at the prompt. normal examples are unaffected and still render inline. addresses #17178
- make the e2e marker assertion output-only: the Rd builds the marker from two halves with cat(sep = ""), so the echoed example source can no longer satisfy the assertion - split command construction into .rs.helpExampleDivertCommand and add unit tests covering the demo branch (blocking, benign, and missing demos) via a fake package in a temporary library - suppress warnings when fetching example/demo source - mirror tools:::httpd()'s separate Example/Demo URL patterns and use regex_match instead of an anchored regex_search - add a back link to the page returned when an example is diverted to the console
🍎 macOS Desktop E2E · ARM64✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · macos-26 ARM64 · commit |
PR Review SummaryReviewed across four aspects: general code quality, test coverage, comment accuracy, and error handling. No critical or merge-blocking issues. The design is sound — every fallback lands on the pre-existing inline path, so the change strictly removes lockups and never makes behavior worse. Critical Issues (0)None. Important Issues (2)1. 2. Back-URL comment is inaccurate, and the link can be dead — Suggestions (5)
Recommended Action
Nothing here blocks merge. The fix is correct, conservative, and well-tested for its core detector; the gaps are in secondary coverage and debuggability rather than behavior. |
gtritchie
left a comment
There was a problem hiding this comment.
LGTM! Some potential additional tests and comment tweaks in the feedback.
- add unit tests for the Example branch of .rs.helpExampleDivertCommand(), using a fabricated installed-package help database, including deparse() quoting and dontrun coverage - cover the full launcher list (bare and namespace-qualified) in the .rs.exampleCodeLaunchesApp() tests - log a warning before swallowing errors when example/demo source can't be retrieved - add type/package/topic context to the C++ LOG_ERROR - correct the back-URL comment (URL topic is the Rd's first alias, so the back-link is best-effort) - document that give.lines = TRUE comments out dontrun blocks, keeping detection consistent with the diverted example() call - tighten the CLAUDE.md --filter wording
|
Thanks for the review! Addressed in 54b9b5a:
One note on the |
Problem
Clicking "Run examples" on a help page whose examples launch a blocking
application (for example a Shiny app via
shiny::runApp()) locks up RStudio,recoverable only by Force Quit (#17178).
R's enhanced HTML help renders "Run examples" inline by knitting the example
code on the R event loop while serving the help HTTP request. A blocking
runApp()there never returns, so the help response never arrives (blankwindow) and the R REPL stays parked (unresponsive console). Running
example("testfn")at the prompt works fine because it executes at the REPLtop level, where a blocking app is interruptible and expected.
Fix
Intercept the
/library/<pkg>/Example/<topic>(andDemo) request in the helpserver. If the example's source statically looks like it launches a blocking
application, run it in the console via
example()/demo()-- matching thebehavior users get at the prompt -- and return a lightweight page instead of
blocking the help server. Normal examples are untouched and still render
inline.
Detection parses the example/demo source and matches
SYMBOL_FUNCTION_CALLtokens against a conservative launcher list (
runApp,runExample,runGadget,shinyApp,run_tutorial, ...), so launcher names appearing onlyin comments or strings do not trigger a false positive.
Known limitation
The launcher list is intentionally conservative (Shiny-family plus
run_tutorial). Other ways an example can block the help server (readline(),plumber::pr_run(),httpuv::runServer(), ...) are not detected and wouldstill wedge the session as before; an undetected case is no worse than current
behavior. The list can grow as such cases are reported.
Testing
test-help.R(--scope r --filter help).statically references
shiny::runApp(guarded byif (FALSE)so it does notactually launch), clicks the real "Run examples" link, and asserts both the
console-routing page and that
example()ran in the console.Fixes #17178.