ComfyUI Node

TG_PydPreview

Preview a pydocmaker report as HTML, right in the graph

By TobiasGlaubach·Created 9 months ago·Updated 9 months ago· 0
TG_PydPreview
  • doc
  • template_params_json
  • STRING
width375
height667
scale1.00
is_portraittrue
template

This is the fun half of the pack

While its sibling TG_PydGetMetadata just reads headers, TG_PydPreview renders a pydocmaker Doc as a live HTML page inside an iframe on the node itself. Turn a report into something you can actually see - text, markdown, tables, figures - without popping a browser tab or exporting a file first. Same caveat as the rest of the pack applies: it only does something if you're feeding it pydocmaker Docs, which come from the author's TG_* Python-execution ecosystem (or a Doc you construct yourself). If you're in that world, this is the payoff node.

How it works

Under the hood it's a two-step render. The node makes sure your doc is a real pydocmaker.Doc (flattening lists, wrapping non-Docs), then calls to_html(template=..., template_params=...) - the library's Jinja2-powered HTML backend. If you don't pass a template, it uses the default one or whatever template the doc's own metadata specifies, and template_params gets merged over the metadata's params, so your overrides win.

The clever part is the front end. A bundled JS extension (js/TG_PydPreview.js) catches the node's output and stuffs the HTML into an iframe widget, sized by your width/height/scale. It also saves the rendered HTML back into the workflow's saved widget values, so your preview survives saving and reloading the workflow - no re-run needed just to see the report again. There's a refresh button on the node in case the iframe goes stale.

The inputs that matter

  • width (INT, default 375) and height (INT, default 667) - treat these as portrait dimensions. The node is set up like a phone-screen report by default.
  • scale (FLOAT, default 1, up to 10) - zooms the preview. Crank it to 2 if 375px is too small to read on a big monitor.
  • is_portrait (BOOLEAN, default true) - if you flip it off, the node swaps width and height, so you get a landscape preview instead. The iframe gets (is_portrait ? width : height) * scale wide and the other way tall.
  • doc (*) - the pydocmaker Doc to render.
  • template (STRING, optional) - a raw Jinja2 template string, if you want to override the doc's own.
  • template_params_json (*, optional) - a dict or JSON string of parameters for that template.

The single output is STRING (as a list) - the rendered HTML itself. The node is an output node (is_output_node: true), so it terminates a branch and shows the iframe; you can also wire the HTML string out to save it to a file if you want the report to persist.

Installing it

Same as its sibling, because it's the same repo:

cd ComfyUI/custom_nodes
git clone https://github.com/TobiasGlaubach/ComfyUI-TG_pydocmaker
cd ComfyUI-TG_pydocmaker
pip install -r requirements.txt

Or search ComfyUI-TG_pydocmaker in ComfyUI Manager. Restart after installing. The only requirement is the pydocmaker pip package, and it drags in a hefty dependency tree (jinja2, markdown, pillow, rich, python-docx...). No model downloads, no API keys - the heavy lifting is all the pip package and Jinja2.

Common issues

  • Iframe shows nothing - hit the refresh button on the node; the extension re-injects the saved HTML. If it's genuinely empty, check that the doc rendered at all by looking at the console, where the node print()s the full HTML. Speaking of which: that console spam is real. Large reports dump hundreds of lines into your terminal every run. Annoying, but harmless.
  • Preview doesn't match the doc's look - you're almost certainly fighting the template system. Either the doc has a template stored in its metadata that's overriding yours, or your template_params_json is malformed (it must parse as JSON / a dict). Pass an explicit template to take control.
  • Nothing renders because there's no source - the pack has exactly two nodes and produces no Docs itself. You need something upstream that builds them. Don't install this expecting a self-contained report tool.
CategoryTG_pydocmaker

Inputs (7)

NameTypeDefaultDescription
widthINT375
heightINT667
scaleFLOAT1.000–10
is_portraitBOOLEANtrue
doc*
templateoptSTRING
template_params_jsonopt*

Outputs (1)

NameTypeDescription
STRINGSTRING