Skip to content

Commit 00a794b

Browse files
committed
Merge branch 'main' of github.com:plotly/plotly.py into notebook-connected-default
2 parents 847b87c + 681d80e commit 00a794b

File tree

6 files changed

+108
-9
lines changed

6 files changed

+108
-9
lines changed

.github/workflows/test-release.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
2+
3+
on:
4+
workflow_dispatch
5+
6+
jobs:
7+
build:
8+
name: Build distribution 📦
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
persist-credentials: false
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.x"
19+
20+
- name: Install Node
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: '18'
24+
25+
- name: Install npm dependencies
26+
run: |
27+
cd js
28+
npm ci --verbose
29+
npm run build --verbose
30+
31+
- name: Install pypa/build
32+
run: >-
33+
python3 -m
34+
pip install
35+
build
36+
--user
37+
- name: Build a binary wheel and a source tarball
38+
run: python3 -m build
39+
- name: Store the distribution packages
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: python-package-distributions
43+
path: dist/
44+
45+
publish-to-testpypi:
46+
name: Publish Python 🐍 distribution 📦 to TestPyPI
47+
needs:
48+
- build
49+
runs-on: ubuntu-latest
50+
51+
environment:
52+
name: testpypi
53+
url: https://test.pypi.org/p/plotly
54+
55+
permissions:
56+
id-token: write # IMPORTANT: mandatory for trusted publishing
57+
58+
steps:
59+
- name: Download all the dists
60+
uses: actions/download-artifact@v4
61+
with:
62+
name: python-package-distributions
63+
path: dist/
64+
- name: Publish distribution 📦 to TestPyPI
65+
uses: pypa/gh-action-pypi-publish@release/v1
66+
with:
67+
repository-url: https://test.pypi.org/legacy/

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## Unreleased
6+
7+
### Fixed
8+
- Fix third-party widget display issues in v6 [[#5102]https://github.com/plotly/plotly.py/pull/5102]
9+
510
## [6.0.1] - 2025-03-14
611

712
### Updated

plotly/basewidget.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ def __init__(
142142
# views of this widget
143143
self._view_count = 0
144144

145+
# Initialize widget layout and data for third-party widget integration
146+
# --------------------------------------------------------------------
147+
self._widget_layout = deepcopy(self._layout_obj._props)
148+
self._widget_data = deepcopy(self._data)
149+
145150
def show(self, *args, **kwargs):
146151
return self
147152

plotly/io/_base_renderers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ def __init__(
253253
auto_play=False,
254254
post_script=None,
255255
animation_opts=None,
256+
include_plotlyjs=True,
256257
):
257258

258259
self.config = dict(config) if config else {}
@@ -262,6 +263,7 @@ def __init__(
262263
self.full_html = full_html
263264
self.animation_opts = animation_opts
264265
self.post_script = post_script
266+
self.include_plotlyjs = "cdn" if self.connected else include_plotlyjs
265267

266268
def activate(self):
267269
if self.global_init:
@@ -306,12 +308,7 @@ def to_mimebundle(self, fig_dict):
306308

307309
from plotly.io import to_html
308310

309-
if self.connected:
310-
include_plotlyjs = "cdn"
311-
include_mathjax = "cdn"
312-
else:
313-
include_plotlyjs = True
314-
include_mathjax = "cdn"
311+
include_mathjax = "cdn"
315312

316313
# build post script
317314
post_script = [
@@ -351,7 +348,7 @@ def to_mimebundle(self, fig_dict):
351348
fig_dict,
352349
config=self.config,
353350
auto_play=self.auto_play,
354-
include_plotlyjs=include_plotlyjs,
351+
include_plotlyjs=self.include_plotlyjs,
355352
include_mathjax=include_mathjax,
356353
post_script=post_script,
357354
full_html=self.full_html,
@@ -384,6 +381,7 @@ def __init__(
384381
auto_play=False,
385382
post_script=None,
386383
animation_opts=None,
384+
include_plotlyjs=False,
387385
):
388386
super(NotebookRenderer, self).__init__(
389387
connected=connected,
@@ -393,6 +391,7 @@ def __init__(
393391
auto_play=auto_play,
394392
post_script=post_script,
395393
animation_opts=animation_opts,
394+
include_plotlyjs=include_plotlyjs,
396395
)
397396

398397

@@ -420,6 +419,7 @@ def __init__(
420419
auto_play=auto_play,
421420
post_script=post_script,
422421
animation_opts=animation_opts,
422+
include_plotlyjs=False,
423423
)
424424

425425

@@ -447,6 +447,7 @@ def __init__(
447447
auto_play=auto_play,
448448
post_script=post_script,
449449
animation_opts=animation_opts,
450+
include_plotlyjs=False,
450451
)
451452

452453

plotly/io/_renderers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ def display_jupyter_version_warnings():
5050
return
5151
elif "jupyter-notebook" in parent_process:
5252
jupyter_notebook = optional_imports.get_module("notebook")
53-
if jupyter_notebook.__version__ < "7":
53+
if jupyter_notebook is not None and jupyter_notebook.__version__ < "7":
5454
# Add warning about upgrading notebook
5555
warnings.warn(
5656
f"Plotly version >= 6 requires Jupyter Notebook >= 7 but you have {jupyter_notebook.__version__} installed.\n To upgrade Jupyter Notebook, please run `pip install notebook --upgrade`."
5757
)
5858
elif "jupyter-lab" in parent_process:
5959
jupyter_lab = optional_imports.get_module("jupyterlab")
60-
if jupyter_lab.__version__ < "3":
60+
if jupyter_lab is not None and jupyter_lab.__version__ < "3":
6161
# Add warning about upgrading jupyterlab
6262
warnings.warn(
6363
f"Plotly version >= 6 requires JupyterLab >= 3 but you have {jupyter_lab.__version__} installed. To upgrade JupyterLab, please run `pip install jupyterlab --upgrade`."
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from unittest import TestCase
2+
import plotly.graph_objs as go
3+
import pytest
4+
5+
try:
6+
go.FigureWidget()
7+
figure_widget_available = True
8+
except ImportError:
9+
figure_widget_available = False
10+
11+
12+
class TestInitialization(TestCase):
13+
if figure_widget_available:
14+
15+
def test_widget_layout_present_on_init(self):
16+
fig = go.FigureWidget(data=go.Scatter(x=[1, 2], y=[1, 2]))
17+
assert fig._widget_layout != {}
18+
19+
def test_widget_data_present_on_init(self):
20+
fig = go.FigureWidget(data=go.Bar(x=[1, 2], y=[1, 2]))
21+
assert fig._widget_data != []

0 commit comments

Comments
 (0)