Skip to content

refactor(examples): mount 01-hello by appending to <body> - #206

Closed
schloerke wants to merge 1 commit into
schloerke/npm-distributionfrom
schloerke/ex1-body-mount
Closed

refactor(examples): mount 01-hello by appending to <body>#206
schloerke wants to merge 1 commit into
schloerke/npm-distributionfrom
schloerke/ex1-body-mount

Conversation

@schloerke

Copy link
Copy Markdown
Collaborator

Stacked on #198 (base schloerke/npm-distribution).

Summary

examples/01-hello no longer ships a #root div. www/index.html is now two lines (stylesheet + deferred script) and app.js creates its own mount container with document.body.appendChild(document.createElement("div")) — safe because the script is deferred, so <body> is fully parsed when it runs.

This prepares 01-hello for the upcoming page_react() page mode, where the server emits no body HTML at all and the client owns its mount point.

Verification

Ran the app and drove it in a browser: no #root element in the DOM, the mount container hangs directly off <body>, typing a name updates both cards, and clicking brings client and server cards to the same count. (Note when trying it locally: www/app.js is served statically with no cache busting, so a hard refresh is needed after pulling this change.)

- Drop the #root div from index.html; app.js creates and appends its
  own mount container (script is deferred, so <body> is parsed)
- Prepares 01-hello for the page_react() mode where the server emits
  no body HTML at all
schloerke added a commit that referenced this pull request Aug 19, 2026
Carries #206's change forward onto the rewritten example. www/index.html is
now two lines (stylesheet + deferred script) and app.js creates its own mount
container via document.body.appendChild(document.createElement("div")) —
safe because the script is deferred, so <body> is parsed when it runs.

This prepares 01-hello for the upcoming page_react() page mode, where the
server emits no body HTML at all and the client owns its mount point.
@schloerke

Copy link
Copy Markdown
Collaborator Author

Superseded by #207, which rebuilds examples/01-hello as Shiny's Old Faithful 01_hello app and carries this change forward — www/index.html is two lines and app.js appends its own mount div to <body>, with the same deferred-script reasoning.

Both PRs rewrite the same three files, so keeping them separate would only produce conflicts. Closing this one; the mount change lives in #207's second commit (refactor(examples): mount 01-hello by appending to <body>).

Note this was stacked on #198 (base schloerke/npm-distribution) while #207 branches off main — if #198 needs the body-mount change on its own branch for unrelated reasons, that will need to be reapplied there.

@schloerke schloerke closed this Aug 19, 2026
schloerke added a commit that referenced this pull request Aug 19, 2026
* docs(01-hello): rebuild example as Shiny's Old Faithful 01_hello

Replaces the name/counter latency demo with Shiny's canonical 01_hello app —
a bins slider over the Old Faithful waiting times — rebuilt ui.tsx-first.

The server never renders a picture. One reactive_output returns histogram
{breaks, counts} as plain JSON plus a caption; www/app.js reads it with
useShinyOutputValue and draws the bars as SVG rects. That contrast with
traditional Shiny's renderPlot({ hist(...) }) is the point of the example.

- faithful.py: waiting times + a stdlib-only binner shared by app.py and
  app-core.py, so the Python side stays dependency-free (no numpy/matplotlib)
- faithful.csv: base R's `faithful` exported for the Python servers; app.R
  uses the built-in dataset and hist(..., plot = FALSE)
- app.R wraps the histogram vectors in I() so bins = 1 serializes as a JSON
  array rather than a scalar, and returns NULL until the client's first bins
  message arrives (Python raises a silent exception instead)
- The chart stays mounted while the server recomputes and only dims via
  useShinyOutputStatus, per the repo's flicker guidance

Verified in a browser against app.py, app-core.py, and app.R: R and Python
produce identical counts at bins 1/2/7/30/50, and the console is clean.

* refactor(examples): mount 01-hello by appending to <body>

Carries #206's change forward onto the rewritten example. www/index.html is
now two lines (stylesheet + deferred script) and app.js creates its own mount
container via document.body.appendChild(document.createElement("div")) —
safe because the script is deferred, so <body> is parsed when it runs.

This prepares 01-hello for the upcoming page_react() page mode, where the
server emits no body HTML at all and the client owns its mount point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant