Skip to content

unaiverse.stats_html_renderer

What this module does 🟢

Renders runtime statistics into a standalone Plotly HTML report for visualization.

stats_html_renderer

Minimal HTML wrapper for the base Stats.plot() output.

Converts a Plotly-format JSON payload ({"data": [...], "layout": {...}}) into a self-contained <!DOCTYPE html> document that renders the chart client-side using Plotly.js loaded from CDN. Python never imports plotly.

render_plotly_html

render_plotly_html(dash_json: str, title: str = 'World Overview') -> str

Wrap a Plotly-format JSON string in a self-contained HTML document.

Substitutes dash_json and title into the module-level _TEMPLATE, producing a complete <!DOCTYPE html> page. The page loads Plotly.js from CDN and calls Plotly.newPlot with the supplied data and layout objects so the chart renders entirely in the browser. No Python plotly dependency is required at runtime.

The returned string can be written directly to a .html file or served over HTTP as text/html. It is typically used by Stats.plot() and World.debug_stats_dashboard() to render live connectivity and performance charts.

Parameters:

Name Type Description Default
dash_json str

A JSON string containing "data" and "layout" keys, as produced by DefaultBaseDash.to_json() or UIPlot.to_json(). The string is inserted verbatim into the <script> block; callers are responsible for ensuring it is valid JSON.

required
title str

The text placed in the HTML <title> element and shown in the browser tab. Defaults to "World Overview".

'World Overview'

Returns:

Type Description
str

A complete <!DOCTYPE html> string with a dark-themed full-viewport chart

str

rendered via Plotly.js 2.35.2 loaded from the official CDN.

Note

The Plotly.js version is fixed at 2.35.2 in the embedded CDN URL. If the CDN is unreachable the page will load but the chart will not render.

Source code in unaiverse/stats_html_renderer.py
def render_plotly_html(dash_json: str, title: str = "World Overview") -> str:
    """Wrap a Plotly-format JSON string in a self-contained HTML document.

    Substitutes ``dash_json`` and ``title`` into the module-level ``_TEMPLATE``,
    producing a complete ``<!DOCTYPE html>`` page. The page loads Plotly.js from CDN
    and calls ``Plotly.newPlot`` with the supplied data and layout objects so the chart
    renders entirely in the browser. No Python plotly dependency is required at runtime.

    The returned string can be written directly to a ``.html`` file or served over HTTP
    as ``text/html``. It is typically used by ``Stats.plot()`` and
    ``World.debug_stats_dashboard()`` to render live connectivity and performance charts.

    Args:
        dash_json: A JSON string containing ``"data"`` and ``"layout"`` keys, as
            produced by ``DefaultBaseDash.to_json()`` or ``UIPlot.to_json()``. The
            string is inserted verbatim into the ``<script>`` block; callers are
            responsible for ensuring it is valid JSON.
        title: The text placed in the HTML ``<title>`` element and shown in the
            browser tab. Defaults to ``"World Overview"``.

    Returns:
        A complete ``<!DOCTYPE html>`` string with a dark-themed full-viewport chart
        rendered via Plotly.js 2.35.2 loaded from the official CDN.

    Note:
        The Plotly.js version is fixed at 2.35.2 in the embedded CDN URL. If the CDN
        is unreachable the page will load but the chart will not render.
    """
    return _TEMPLATE.format(title=title, dash_json=dash_json)