ui.page_html

ui.page_html(html, *, extra_deps=None, deps_replace_pattern=DEPS_PLACEHOLDER)

Create a page from a complete HTML document that you own.

Use this as App(ui=) when your app's UI is a complete HTML document – the index.html a JS bundler emits, say – rather than one Shiny builds for you from ui.page_*() components. The document is served as-is, with Shiny's own HTML dependencies (and any in extra_deps) inserted at deps_replace_pattern, and their files served by the app.

Parameters

html : str | Path

A complete HTML document, including <html>, as a string – or a Path to an HTML file, which is read (as UTF-8) each time this function is called. It must contain deps_replace_pattern to mark where the dependencies are inserted.

extra_deps : ListOrTuple[HTMLDependency] | None = None

Additional HTML dependencies to include, alongside Shiny’s own. These are inserted after Shiny’s, and their files are served by the app.

deps_replace_pattern : str = DEPS_PLACEHOLDER

The string in html to replace with Shiny’s dependencies. Only the first instance is replaced. Defaults to '<meta name="shiny-dependency-placeholder" content="">'.

Returns

: PageHtmlDocument

A document object to pass as App(ui=), or to return from a UI function (App(ui=lambda request: ...), which is what bookmarking requires).

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
from pathlib import Path

from shiny import App, Inputs, Outputs, Session, render, ui

app_ui = ui.page_html(Path(__file__).parent / "index.html")


def server(input: Inputs, output: Outputs, session: Session):
    @render.text
    def greeting():
        return "Hello from the server!"


app = App(app_ui, server)


## file: index.html
<!DOCTYPE html>
<html>
  <head>
    <title>A page Shiny did not build</title>
    <!-- A meta tag that is replaced with shiny's dependencies (and any provided `extra_deps=`) -->
    <meta name="shiny-dependency-placeholder" content="">
  </head>
  <body>
    <h1>A complete HTML document, served as-is</h1>
    <div id="greeting" class="shiny-text-output"></div>
  </body>
</html>