Skip to content

Commit 3b461a7

Browse files
committed
feat: make div_id configurable
implements #3487 (comment)
1 parent bed8c1b commit 3b461a7

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Diff for: packages/python/plotly/plotly/io/_html.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def to_html(
3838
default_width="100%",
3939
default_height="100%",
4040
validate=True,
41+
div_id=None,
4142
):
4243
"""
4344
Convert a figure to an HTML string representation.
@@ -135,7 +136,7 @@ def to_html(
135136
fig_dict = validate_coerce_fig_to_dict(fig, validate)
136137

137138
# ## Generate div id ##
138-
plotdivid = "plotly-root"
139+
plotdivid = div_id or str(uuid.uuid4())
139140

140141
# ## Serialize figure ##
141142
jdata = to_json_plotly(fig_dict.get("data", []))
@@ -391,6 +392,7 @@ def write_html(
391392
default_width="100%",
392393
default_height="100%",
393394
auto_open=False,
395+
div_id=None,
394396
):
395397
"""
396398
Write a figure to an HTML file representation
@@ -512,6 +514,7 @@ def write_html(
512514
default_width=default_width,
513515
default_height=default_height,
514516
validate=validate,
517+
div_id=div_id,
515518
)
516519

517520
# Check if file is a string

Diff for: packages/python/plotly/plotly/tests/test_io/test_html.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_versioned_cdn_included(fig1):
4141

4242

4343
def test_html_deterministic(fig1):
44-
assert pio.to_html(fig1, include_plotlyjs="cdn") == pio.to_html(
45-
fig1, include_plotlyjs="cdn"
44+
div_id = "plotly-root"
45+
assert pio.to_html(fig1, include_plotlyjs="cdn", div_id=div_id) == pio.to_html(
46+
fig1, include_plotlyjs="cdn", div_id=div_id
4647
)

0 commit comments

Comments
 (0)