Conversation
preswald/utils/__init__.py
Outdated
There was a problem hiding this comment.
Let's keep all of this in utils.py for now, instead of creating a separate file. Once this change is in, then we can refactor
preswald/utils/exporter.py
Outdated
There was a problem hiding this comment.
See above comment - this should also just go in utils.py - we can refactor afterwards
a4ebac4 to
299644f
Compare
shivam-singhal
left a comment
There was a problem hiding this comment.
@Ani665458 last nit - can you move the imports and also include playwright in the pyproject toml dependencies? it should look like below (because it is not a pure python wheel and can't be installed within pyodide)
"playwright>=1.50; platform_system != 'Emscripten'"
| from typing import Optional | ||
|
|
||
| import toml | ||
| from playwright.sync_api import TimeoutError as PlaywrightTimeoutError |
There was a problem hiding this comment.
Since these dependencies are only used within the export_app_to_pdf function, they should only be imported within the function context.
| # Wait for Plotly charts to fully render | ||
| try: | ||
| print("⏳ Waiting for Plotly chart containers...") | ||
| page.wait_for_selector("div.js-plotly-plot", timeout=40000) |
There was a problem hiding this comment.
1/ what if there are not plotly charts declared?
| print("⏳ Waiting for Plotly chart containers...") | ||
| page.wait_for_selector("div.js-plotly-plot", timeout=40000) | ||
|
|
||
| charts = page.query_selector_all("div.js-plotly-plot") |
There was a problem hiding this comment.
1/ why special handling for charts?
| print(f"🧪 Waiting for chart {i + 1} to render...") | ||
| chart.wait_for_selector("svg", timeout=30000) | ||
|
|
||
| page.wait_for_timeout(2000) # Extra safety buffer |
There was a problem hiding this comment.
1/ the hardcoding of the timeout itself is very bad, diff machines with diff sys resources take diff amount of time to get the websocket data propagated and get rendered on the page, so we should not do this wait for
change this to:
1/ declare unique html id for each frontend component
2/ get the components declared by the user in the script and check whether all are rendered on the page
6ac1dad to
bdb2c4e
Compare
This PR introduces a new export CLI command to generate print-ready PDF reports from Preswald visualizations using Playwright. Key highlights include:
✅ Features:
preswald export --format pdf --output output/report.pdf
Renders the current app and exports a snapshot to a PDF.
Uses Playwright to navigate to the local app (http://localhost:8501 by default), waits for charts to render, and captures the full page to a PDF.
-Modular design:
Added preswald/utils/exporter.py to encapsulate export logic.
-Updated cli.py to wire up the new command.
Introduced preswald/utils/init.py with utility functions like logging.
-Graph rendering wait:
The export command includes a configurable delay to wait for Plotly charts and other async content to finish rendering.
Refactored utility imports and logging setup.
Improved error handling for Playwright export failures.
📦 Example usage:
preswald run # In one terminal
preswald export --format pdf --output app-report.pdf # In another