Skip to main content

page_react_html

page_react_html(
    path='www/index.html',
    *,
    extra_deps=None,
    shinyreact_js='server',
)

Serve a React index.html document (the ui.tsx pattern, Core API).

Reads a complete HTML document — the kind a Vite build emits — and injects Shiny’s and shinyreact’s dependencies into it. The document must contain Shiny’s dependency placeholder in <head>::

<meta name="shiny-dependency-placeholder" content="">

The script/link tags render in its place; the same literal is py-shiny’s own DEPS_PLACEHOLDER. It is an ordinary <meta> tag rather than template syntax, so the document stays valid HTML that a bundler’s dev server can serve unchanged. Matches R’s page_react_html().

You rarely need to call this yourself — :class:shinyreact.ReactApp discovers www/index.html and calls it for you::

from shinyreact import ReactApp

app = ReactApp(server)

Call it directly to pass a non-default path (ReactApp(server, ui=page_react_html("client/index.html"))). shiny.App works too (via ui.page_html(), py-shiny#2475), but only ReactApp mounts the document’s directory at /, so the assets the document references (your bundle’s JS/CSS) are served when they live next to it (conventionally www/).

For apps that don’t need to own the HTML document, prefer :func:page_react — it requires no HTML file at all and works with plain shiny.App.

Args: path: Path to the HTML document. Absolute paths are used verbatim; relative paths resolve against the caller module’s directory, or against :func:pathlib.Path.cwd when there is no caller __file__. Defaults to "www/index.html". extra_deps: Additional :class:~htmltools.HTMLDependency objects to render at the placeholder. A full document has no tag tree to attach dependencies to, so this is the only way in — the counterpart of :func:page_react’s positional *args. They render after Shiny’s and shinyreact’s, so they can rely on window.shinyreact existing. shinyreact_js: Who supplies shinyreact.js / shinyreact.css: "server" (default) or "client" for an npm-tier app whose bundle imports @posit-dev/shinyreact — see :func:page_react.