plotly / plotly/plotly.py

make generated plot HTML reproducible

Open
#3,393 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

The HTML/js contains UUIDs generated by python's built-in uuid.uuid4. By nature, those are unique and totally random.

But if you generate documents as part of a pipeline (e.g. via https://dvc.org/ ) then it would be great to have them reproducible down to the byte.

import plotly.express as px

fig =px.scatter(x=range(10), y=range(10))
fig.write_html("file1.html")
fig.write_html("file2.html")

The files will be identical except from the UUIDs.

I "solved" this problem by monkey-patching the relevant function:

# monkey patch
import uuid
import random

uuid4_rnd = random.Random(0)
def uuid4_seeded():
    """Generate a random UUID using random.Random"""
    return uuid.UUID(bytes=uuid4_rnd.randbytes(16), version=4)

uuid.uuid4 = uuid4_seeded

fig =px.scatter(x=range(10), y=range(10))
fig.write_html("file.html")

re-executing this snippet will produce identical files.

It would be great to exchange one function (or set a seed for an internal version of uuid) in plotly instead of hijacking the python built-in.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the fig.write_html entry point and trace where UUIDs are inserted into the generated HTML/JavaScript. Compare repeated writes of the example figure and determine how Plotly should expose deterministic UUID generation or seeding. Done means identical byte-for-byte HTML files can be generated without monkey-patching Python's uuid.uuid4.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.