Support setting plotly.js path for Kaleido v1 image export by emilykl · Pull Request #5207 · plotly/plotly.py · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plotly/io/_defaults.py
27 changes: 13 additions & 14 deletions plotly/io/_kaleido.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ def to_image(
from kaleido.errors import ChromeNotFoundError

try:
kopts = {}
if defaults.plotlyjs:
kopts["plotlyjs"] = defaults.plotlyjs
if defaults.mathjax:
kopts["mathjax"] = defaults.mathjax

# TODO: Refactor to make it possible to use a shared Kaleido instance here
img_bytes = kaleido.calc_fig_sync(
fig_dict,
Expand All @@ -379,13 +385,7 @@ def to_image(
scale=scale or defaults.default_scale,
),
topojson=defaults.topojson,
kopts=(
dict(
mathjax=defaults.mathjax,
)
if defaults.mathjax
else None
),
kopts=kopts,
)
except ChromeNotFoundError:
raise RuntimeError(PLOTLY_GET_CHROME_ERROR_MSG)
Expand Down Expand Up @@ -692,15 +692,14 @@ def write_images(
from kaleido.errors import ChromeNotFoundError

try:
kopts = {}
if defaults.plotlyjs:
kopts["plotlyjs"] = defaults.plotlyjs
if defaults.mathjax:
kopts["mathjax"] = defaults.mathjax
kaleido.write_fig_from_object_sync(
kaleido_specs,
kopts=(
dict(
mathjax=defaults.mathjax,
)
if defaults.mathjax
else None
),
kopts=kopts,
)
except ChromeNotFoundError:
raise RuntimeError(PLOTLY_GET_CHROME_ERROR_MSG)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [

[project.optional-dependencies]
express = ["numpy"]
kaleido = ["kaleido==1.0.0rc13"]
kaleido = ["kaleido==1.0.0rc15"]
dev = ["black==25.1.0"]

[project.scripts]
Expand Down
2 changes: 1 addition & 1 deletion test_requirements/requirements_optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ matplotlib
scikit-image
psutil
# kaleido>=1.0.0 # Uncomment and delete line below once Kaleido v1 is released
kaleido==1.0.0rc13
kaleido==1.0.0rc15
orjson
polars[timezone]
pyarrow
Expand Down
94 changes: 92 additions & 2 deletions tests/test_optional/test_kaleido/test_kaleido.py