Skip to content

Support setting plotly.js path for Kaleido v1 image export #5207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self):
self.default_scale = 1
self.mathjax = None
self.topojson = None
self.plotlyjs = None


defaults = _Defaults()
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