Skip to content

Fix loading of Plotly JSON files serialized without pretty-printing#185

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-plotly-json-load-error
Draft

Fix loading of Plotly JSON files serialized without pretty-printing#185
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-plotly-json-load-error

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 29, 2026

When Plotly serializes a figure to JSON without pretty-printing (plotly_json(p, pretty=FALSE) in R), large numeric arrays are encoded as binary TypedArrays instead of standard JSON arrays:

{"dtype": "f8", "bdata": "UAyNjdA7uD9A...", "shape": "10, 8"}

st.plotly_chart() cannot render these objects, causing the Streamlit report to error. Pretty-printed JSON uses plain arrays and works fine.

Changes

  • src/vuegen/plot_utils.py — New decode_plotly_json() utility that recursively walks a parsed JSON object and decodes any {"dtype", "bdata"} TypedArray dict to a Python list. Supports all NumPy dtype codes (i1i8, u1u8, f4, f8) and handles 2-D shape reshaping.

  • src/vuegen/streamlit_reportview.py — Generated Plotly section code now calls plot_utils.decode_plotly_json(plot_json) immediately after JSON loading (both local files and URL fetches). from vuegen import plot_utils is injected into generated imports.

  • tests/test_plot_utils.py — Tests covering all dtype codes, 1-D/2-D shape handling, recursive decoding, and round-trip validation against the actual JSON files from the issue report.

  • Test data & example report files — Added the issue's two example JSON files to example data; updated reference Streamlit section scripts to match the new generated output.

Copilot AI changed the title [WIP] Fix error loading plotly JSON files without pretty argument Fix loading of Plotly JSON files serialized without pretty-printing Apr 29, 2026
Copilot AI requested a review from enryH April 29, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error to load plotly JSON files generated without the "pretty=TRUE" argument - Streamlit report

2 participants