set_react_page
set_react_page(path=None, *, shinyreact_js='server')Set the page for this Express app to a React app (the ui.tsx pattern).
With no arguments, serves www/index.html when it exists; otherwise falls back to :func:page_react-style discovery of www/ui.js / www/ui.css, emitting no body HTML at all (your JS appends its own mount container to <body>). Passing path explicitly requires the file to exist.
When an HTML file is used, it is read once (cached at call time) and used as the page body. In both modes, dependencies from traditional Shiny renderers (e.g. @render.data_frame) are discovered automatically and injected into the page head.
Renderers defined inside @module.server are discovered too: every renderer mounted while the app body runs is found via the session’s registered outputs, so module components load their JS/CSS with no extra configuration. Renderers mounted dynamically after page load (e.g. a module server called inside a @reactive.effect) are not in the initial page; when their UI is delivered through Shiny’s dynamic-UI path (@render.ui), Shiny injects their dependencies on render.
.. note::
Edits to index.html require restarting the Shiny server — see the comment in :func:_build_react_page_fn for the upstream Shiny Express constraint that prevents per-request re-reads.
Path resolution
path resolution depends on whether it is absolute or relative:
Absolute path: used verbatim, regardless of caller or CWD::
# /tmp/standalone-app.py from shinyreact import set_react_page set_react_page("/srv/myapp/www/index.html") # → reads /srv/myapp/www/index.htmlRelative path from a module (typical): resolved against the caller’s module directory (read from the calling frame’s
__file__)::# /path/to/my-app/app.py from shinyreact import set_react_page set_react_page() # → /path/to/my-app/www/index.html set_react_page("static/index.html") # → /path/to/my-app/static/index.htmlThis is the expected usage for
shiny run app.py.Relative path with no caller
__file__(REPL / exec’d code): falls back to :func:pathlib.Path.cwd— the current working directory of the process. Same convention CLI tools use for relative paths::>>> import os, shinyreact >>> os.chdir("/path/to/my-app") >>> shinyreact.set_react_page() # → /path/to/my-app/www/index.html >>> shinyreact.set_react_page("a.html") # → /path/to/my-app/a.htmlThe fallback is deliberate — call from any working directory and you get a predictable result. If you need a specific path regardless of CWD, pass an absolute path (case 1).
Args: path: Path to the HTML file. Absolute paths are used verbatim; relative paths resolve against the caller module’s directory, or against Path.cwd() when there is no caller __file__. When None (the default), uses www/index.html if it exists, else discovers www/ui.js / www/ui.css. 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.