From f1a88edd072b669c030b920693f39dd533c8df96 Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Wed, 19 Oct 2022 21:22:13 +0000 Subject: [PATCH 1/7] Prefer use of _repr_mimebundle_ in BaseFigureWidget Using an existing function in renderers that fixes issues in classic notebooks --- packages/python/plotly/plotly/basedatatypes.py | 10 +--------- packages/python/plotly/plotly/basewidget.py | 9 +++++++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 1a7cbb8007..0f9ff15e2d 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -819,18 +819,10 @@ def _repr_mimebundle_(self, include=None, exclude=None, validate=True, **kwargs) renderer_str = pio.renderers.default renderers = pio._renderers.renderers - renderer_names = renderers._validate_coerce_renderers(renderer_str) - renderers_list = [renderers[name] for name in renderer_names] from plotly.io._utils import validate_coerce_fig_to_dict - from plotly.io._renderers import MimetypeRenderer fig_dict = validate_coerce_fig_to_dict(self, validate) - # Mimetype renderers - bundle = {} - for renderer in renderers_list: - if isinstance(renderer, MimetypeRenderer): - bundle.update(renderer.to_mimebundle(fig_dict)) - return bundle + return renderers._build_mime_bundle(fig_dict, renderer_str, **kwargs) def _ipython_display_(self): """ diff --git a/packages/python/plotly/plotly/basewidget.py b/packages/python/plotly/plotly/basewidget.py index 27cd8c7e99..0ecf2e97d3 100644 --- a/packages/python/plotly/plotly/basewidget.py +++ b/packages/python/plotly/plotly/basewidget.py @@ -733,12 +733,17 @@ def _handler_js2py_pointsCallback(self, change): # Display # ------- + def _repr_html_(self): + """ + Customize html representation + """ + raise NotImplementedError # Prefer _repr_mimebundle_ + def _ipython_display_(self): """ Handle rich display of figures in ipython contexts """ - # Override BaseFigure's display to make sure we display the widget version - widgets.DOMWidget._ipython_display_(self) + raise NotImplementedError # Prefer _repr_mimebundle_ # Callbacks # --------- From eb80f50442fa3e98f6811c6624a95f5788b01e39 Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Thu, 13 Oct 2022 14:21:12 -0700 Subject: [PATCH 2/7] Bump @jupyter-widgets/base to 6.0.1 --- .../jupyterlab-plotly/package-lock.json | 182 ++++++++++++++---- .../javascript/jupyterlab-plotly/package.json | 2 +- 2 files changed, 144 insertions(+), 40 deletions(-) diff --git a/packages/javascript/jupyterlab-plotly/package-lock.json b/packages/javascript/jupyterlab-plotly/package-lock.json index 646567cd4b..f3bf770225 100644 --- a/packages/javascript/jupyterlab-plotly/package-lock.json +++ b/packages/javascript/jupyterlab-plotly/package-lock.json @@ -68,20 +68,129 @@ } }, "@jupyter-widgets/base": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@jupyter-widgets/base/-/base-4.0.0.tgz", - "integrity": "sha512-lBQgLYzq6C+XjfVJTidk+rckKo/+xlTgIm1XUtACA3BUz8bgi2du2zmbYkcrplJMwGub4QWP6GnKgM5ZZRhzYg==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@jupyter-widgets/base/-/base-6.0.1.tgz", + "integrity": "sha512-EDuEaM10WtLYvqAaC8nXl0lmss8P+pDPtFIsCmRiodZNg3xyXAxTHDJM9Gl5gtXk31ny62Y+C7l275uir1/0sw==", "requires": { "@jupyterlab/services": "^6.0.0", - "@lumino/coreutils": "^1.2.0", - "@lumino/messaging": "^1.2.1", - "@lumino/widgets": "^1.3.0", - "@types/backbone": "^1.4.1", + "@lumino/coreutils": "^1.11.1", + "@lumino/messaging": "^1.10.1", + "@lumino/widgets": "^1.30.0", + "@types/backbone": "1.4.14", "@types/lodash": "^4.14.134", - "backbone": "1.2.3", - "base64-js": "^1.2.1", + "backbone": "1.4.0", "jquery": "^3.1.1", "lodash": "^4.17.4" + }, + "dependencies": { + "@lumino/algorithm": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/@lumino/algorithm/-/algorithm-1.9.2.tgz", + "integrity": "sha512-Z06lp/yuhz8CtIir3PNTGnuk7909eXt4ukJsCzChsGuot2l5Fbs96RJ/FOHgwCedaX74CtxPjXHXoszFbUA+4A==" + }, + "@lumino/collections": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/@lumino/collections/-/collections-1.9.3.tgz", + "integrity": "sha512-2i2Wf1xnfTgEgdyKEpqM16bcYRIhUOGCDzaVCEZACVG9R1CgYwOe3zfn71slBQOVSjjRgwYrgLXu4MBpt6YK+g==", + "requires": { + "@lumino/algorithm": "^1.9.2" + } + }, + "@lumino/commands": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/@lumino/commands/-/commands-1.20.1.tgz", + "integrity": "sha512-7u0vc3qWVAyI3CHGmQ+MXP5bvmj5dtnU5J4u2aRrodtlysU3nLjGhD57bbTq2VUqpmS1bkfBqNFhO1e4PFKSaQ==", + "requires": { + "@lumino/algorithm": "^1.9.2", + "@lumino/coreutils": "^1.12.1", + "@lumino/disposable": "^1.10.2", + "@lumino/domutils": "^1.8.2", + "@lumino/keyboard": "^1.8.2", + "@lumino/signaling": "^1.10.2", + "@lumino/virtualdom": "^1.14.2" + } + }, + "@lumino/coreutils": { + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@lumino/coreutils/-/coreutils-1.12.1.tgz", + "integrity": "sha512-JLu3nTHzJk9N8ohZ85u75YxemMrmDzJdNgZztfP7F7T7mxND3YVNCkJG35a6aJ7edu1sIgCjBxOvV+hv27iYvQ==" + }, + "@lumino/disposable": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/@lumino/disposable/-/disposable-1.10.2.tgz", + "integrity": "sha512-jwt8bCw3OU65wJMOCJUZAfVVUdxZdEufRDrDkoG91aSW+/R/VBzt33AqZX81/B0KxddL6R3PdNWI+0fRJBaeYw==", + "requires": { + "@lumino/algorithm": "^1.9.2", + "@lumino/signaling": "^1.10.2" + } + }, + "@lumino/domutils": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@lumino/domutils/-/domutils-1.8.2.tgz", + "integrity": "sha512-QIpMfkPJrs4GrWBuJf2Sn1fpyVPmvqUUAeD8xAQo8+4V5JAT0vUDLxZ9HijefMgNCi3+Bs8Z3lQwRCrz+cFP1A==" + }, + "@lumino/dragdrop": { + "version": "1.14.2", + "resolved": "https://registry.npmjs.org/@lumino/dragdrop/-/dragdrop-1.14.2.tgz", + "integrity": "sha512-wXsungIpgNSLmV23f61UPhDlxr0VUBX4xQY2gHq0ps1dDL9BNQnec9q0dbeYRa0n27gKEJ81efAgCV4a/+xJ3A==", + "requires": { + "@lumino/coreutils": "^1.12.1", + "@lumino/disposable": "^1.10.2" + } + }, + "@lumino/keyboard": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@lumino/keyboard/-/keyboard-1.8.2.tgz", + "integrity": "sha512-Dy+XqQ1wXbcnuYtjys5A0pAqf4SpAFl9NY6owyIhXAo0Va7w3LYp3jgiP1xAaBAwMuUppiUAfrbjrysZuZ625g==" + }, + "@lumino/messaging": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/@lumino/messaging/-/messaging-1.10.3.tgz", + "integrity": "sha512-F/KOwMCdqvdEG8CYAJcBSadzp6aI7a47Fr60zAKGqZATSRRRV41q53iXU7HjFPqQqQIvdn9Z7J32rBEAyQAzww==", + "requires": { + "@lumino/algorithm": "^1.9.2", + "@lumino/collections": "^1.9.3" + } + }, + "@lumino/properties": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@lumino/properties/-/properties-1.8.2.tgz", + "integrity": "sha512-EkjI9Cw8R0U+xC9HxdFSu7X1tz1H1vKu20cGvJ2gU+CXlMB1DvoYJCYxCThByHZ+kURTAap4SE5x8HvKwNPbig==" + }, + "@lumino/signaling": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/@lumino/signaling/-/signaling-1.10.2.tgz", + "integrity": "sha512-LvnLRb2ngOZbRtFHRcKkMdPSXm0bzfVv/5mbx/hpT1DWHihMtBpGQ+bIfFvnARmFJoI11Wt+DMX77MWPw6tpig==", + "requires": { + "@lumino/algorithm": "^1.9.2" + } + }, + "@lumino/virtualdom": { + "version": "1.14.2", + "resolved": "https://registry.npmjs.org/@lumino/virtualdom/-/virtualdom-1.14.2.tgz", + "integrity": "sha512-iF20v6s4gP/hAH4VjmBtv2dexr18W4vL/Y5Rx4+U3kS/ZIFU7987NsM+0Yr6W9kdBQ1w6+pJjRBS9sWYnohdoQ==", + "requires": { + "@lumino/algorithm": "^1.9.2" + } + }, + "@lumino/widgets": { + "version": "1.34.1", + "resolved": "https://registry.npmjs.org/@lumino/widgets/-/widgets-1.34.1.tgz", + "integrity": "sha512-DNpqg7TgAQROOVytGNgFs8oBET/UrTjXYEls/S/GSzr0qcoiDHfrX+LOyaXxOO08ijvq9NhqYfYvmM5AFGTNuA==", + "requires": { + "@lumino/algorithm": "^1.9.2", + "@lumino/commands": "^1.20.1", + "@lumino/coreutils": "^1.12.1", + "@lumino/disposable": "^1.10.2", + "@lumino/domutils": "^1.8.2", + "@lumino/dragdrop": "^1.14.2", + "@lumino/keyboard": "^1.8.2", + "@lumino/messaging": "^1.10.3", + "@lumino/properties": "^1.8.2", + "@lumino/signaling": "^1.10.2", + "@lumino/virtualdom": "^1.14.2" + } + } } }, "@jupyterlab/builder": { @@ -947,9 +1056,9 @@ } }, "@types/backbone": { - "version": "1.4.10", - "resolved": "https://registry.npmjs.org/@types/backbone/-/backbone-1.4.10.tgz", - "integrity": "sha512-X6UM8N9i4WFtO1F53Z3DE7mjI7UxEfxyFtMTYHOPFhYFvExDuu0UJENstnA023+/FnVOdxltMIKc4picZxW4dA==", + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@types/backbone/-/backbone-1.4.14.tgz", + "integrity": "sha512-85ldQ99fiYTJFBlZuAJRaCdvTZKZ2p1fSs3fVf+6Ub6k1X0g0hNJ0qJ/2FOByyyAQYLtbEz3shX5taKQfBKBDw==", "requires": { "@types/jquery": "*", "@types/underscore": "*" @@ -998,9 +1107,9 @@ } }, "@types/jquery": { - "version": "3.5.5", - "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.5.tgz", - "integrity": "sha512-6RXU9Xzpc6vxNrS6FPPapN1SxSHgQ336WC6Jj/N8q30OiaBZ00l1GBgeP7usjVZPivSkGUfL1z/WW6TX989M+w==", + "version": "3.5.14", + "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.14.tgz", + "integrity": "sha512-X1gtMRMbziVQkErhTQmSe2jFwwENA/Zr+PprCkF63vFq+Yt5PZ4AlKqgmeNlwgn7dhsXEK888eIW2520EpC+xg==", "requires": { "@types/sizzle": "*" } @@ -1012,9 +1121,9 @@ "dev": true }, "@types/lodash": { - "version": "4.14.168", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.168.tgz", - "integrity": "sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q==" + "version": "4.14.186", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.186.tgz", + "integrity": "sha512-eHcVlLXP0c2FlMPm56ITode2AgLMSa6aJ05JTTbYbI+7EMkCEE5qk2E41d5g2lCVTqRe0GnnRFurmlCsDODrPw==" }, "@types/minimatch": { "version": "3.0.4", @@ -1038,14 +1147,14 @@ } }, "@types/sizzle": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.2.tgz", - "integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==" + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.3.tgz", + "integrity": "sha512-JYM8x9EGF163bEyhdJBpR2QX1R5naCJHC8ucJylJ3w9/CVBaskdQ8WqBf8MmQrd1kRvp/a4TS8HJ+bxzR7ZJYQ==" }, "@types/underscore": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.11.1.tgz", - "integrity": "sha512-mW23Xkp9HYgdMV7gnwuzqnPx6aG0J7xg/b7erQszOcyOizWylwCr9cgYM/BVVJHezUDxwyigG6+wCFQwCvyMBw==" + "version": "1.11.4", + "resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.11.4.tgz", + "integrity": "sha512-uO4CD2ELOjw8tasUrAhvnn2W4A0ZECOvMjCivJr4gA9pGgjv+qxKWY9GLTMVEK8ej85BxQOocUyE7hImmSQYcg==" }, "@types/webpack-env": { "version": "1.16.0", @@ -1367,11 +1476,11 @@ "integrity": "sha512-LEeSAWeh2Gfa2FtlQE1shxQ8zi5F9GHarrGKz08TMdODD5T4eH6BMsvtnhbWZ+XQn+Gb6om/917ucvRu7l7ukw==" }, "backbone": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/backbone/-/backbone-1.2.3.tgz", - "integrity": "sha1-wiz9B/yG676uYdGJKe0RXpmdZbk=", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/backbone/-/backbone-1.4.0.tgz", + "integrity": "sha512-RLmDrRXkVdouTg38jcgHhyQ/2zjg7a8E6sz2zxfz21Hh17xDJYUHBZimVIt5fUyS8vbfpeSmTL3gUjTEvUV3qQ==", "requires": { - "underscore": ">=1.7.0" + "underscore": ">=1.8.3" } }, "balanced-match": { @@ -1380,11 +1489,6 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, - "base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" - }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -3466,9 +3570,9 @@ } }, "jquery": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", - "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==" + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.1.tgz", + "integrity": "sha512-opJeO4nCucVnsjiXOE+/PcCgYw9Gwpvs/a6B1LL/lQhwWwpbVEVYDZ1FokFr8PRc7ghYlrFPuyHuiiDNTQxmcw==" }, "json-buffer": { "version": "3.0.0", @@ -5653,9 +5757,9 @@ } }, "underscore": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.1.tgz", - "integrity": "sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw==" + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz", + "integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==" }, "uniq": { "version": "1.0.1", diff --git a/packages/javascript/jupyterlab-plotly/package.json b/packages/javascript/jupyterlab-plotly/package.json index 516f017c63..76e0d274a9 100644 --- a/packages/javascript/jupyterlab-plotly/package.json +++ b/packages/javascript/jupyterlab-plotly/package.json @@ -60,7 +60,7 @@ "webpack-cli": "^4.0.0" }, "dependencies": { - "@jupyter-widgets/base": "^2.0.0 || ^3.0.0 || ^4.0.0", + "@jupyter-widgets/base": ">=2.0.0 <7.0.0", "@jupyterlab/rendermime-interfaces": "^1.3.0 || ^2.0.0 || ^3.0.0", "@lumino/messaging": "^1.2.3", "@lumino/widgets": "^1.8.1", From 9ec031dab53a455d323f6d0ab9d72faac8f806f9 Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Tue, 11 Oct 2022 23:13:58 -0700 Subject: [PATCH 3/7] Process Lumino messages with compatibility with Phosphor See jupyter-widgets/ipywidgets/pull/3124 for resize change rationale --- .../jupyterlab-plotly/src/Figure.ts | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/javascript/jupyterlab-plotly/src/Figure.ts b/packages/javascript/jupyterlab-plotly/src/Figure.ts index 677d250379..cbebe79b00 100644 --- a/packages/javascript/jupyterlab-plotly/src/Figure.ts +++ b/packages/javascript/jupyterlab-plotly/src/Figure.ts @@ -716,7 +716,10 @@ export class FigureModel extends DOMWidgetModel { static serializers: ISerializers = { ...DOMWidgetModel.serializers, - _data: { deserialize: py2js_deserializer, serialize: js2py_serializer }, + _data: { + deserialize: py2js_deserializer, + serialize: js2py_serializer, + }, _layout: { deserialize: py2js_deserializer, serialize: js2py_serializer, @@ -806,7 +809,7 @@ export class FigureView extends DOMWidgetView { viewID: string; /** - * The perform_render method is called by processPhosphorMessage + * The perform_render method is called by processLuminoMessage * after the widget's DOM element has been attached to the notebook * output cell. This happens after the initialize of the * FigureModel, and it won't happen at all if the Python FigureWidget @@ -900,10 +903,10 @@ export class FigureView extends DOMWidgetView { } /** - * Respond to phosphorjs events + * Respond to Lumino events */ - processPhosphorMessage(msg: any) { - super.processPhosphorMessage.apply(this, arguments); + _processLuminoMessage(msg: any, _super: any) { + _super.apply(this, arguments); var that = this; switch (msg.type) { case "before-attach": @@ -921,10 +924,6 @@ export class FigureView extends DOMWidgetView { xaxis: axisHidden, yaxis: axisHidden, }); - - window.addEventListener("resize", function () { - that.autosizeFigure(); - }); break; case "after-attach": // Rendering actual figure in the after-attach event allows @@ -938,6 +937,21 @@ export class FigureView extends DOMWidgetView { } } + processPhosphorMessage(msg: any) { + this._processLuminoMessage(msg, super["processPhosphorMessage"]); + + var that = this; + if (msg.type === "before-attach") { + window.addEventListener("resize", function () { + that.autosizeFigure(); + }); + } + } + + processLuminoMessage(msg: any) { + this._processLuminoMessage(msg, super["processLuminoMessage"]); + } + autosizeFigure() { var that = this; var layout = that.model.get("_layout"); From ec808feb194fff7ceea6834aab766dd7c5e5ec74 Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Thu, 20 Oct 2022 00:22:51 +0000 Subject: [PATCH 4/7] Bump versions of ipywidgets and ipython in tests --- .../plotly/test_requirements/requirements_36_optional.txt | 2 +- .../plotly/test_requirements/requirements_37_optional.txt | 2 +- .../plotly/test_requirements/requirements_38_optional.txt | 2 +- .../plotly/test_requirements/requirements_39_optional.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/python/plotly/test_requirements/requirements_36_optional.txt b/packages/python/plotly/test_requirements/requirements_36_optional.txt index 8c33824da6..3fb4185e9c 100644 --- a/packages/python/plotly/test_requirements/requirements_36_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_36_optional.txt @@ -7,7 +7,7 @@ statsmodels==0.10.2 pillow==5.2.0 pytest==3.5.1 pytz==2016.10 -ipython[all]==5.1.0 +ipython[all]==5.4.0 ipywidgets==7.2.0 ipykernel==4.8.2 jupyter==1.0.0 diff --git a/packages/python/plotly/test_requirements/requirements_37_optional.txt b/packages/python/plotly/test_requirements/requirements_37_optional.txt index 8c33824da6..3fb4185e9c 100644 --- a/packages/python/plotly/test_requirements/requirements_37_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_37_optional.txt @@ -7,7 +7,7 @@ statsmodels==0.10.2 pillow==5.2.0 pytest==3.5.1 pytz==2016.10 -ipython[all]==5.1.0 +ipython[all]==5.4.0 ipywidgets==7.2.0 ipykernel==4.8.2 jupyter==1.0.0 diff --git a/packages/python/plotly/test_requirements/requirements_38_optional.txt b/packages/python/plotly/test_requirements/requirements_38_optional.txt index 411c9c0f15..34b686ad02 100644 --- a/packages/python/plotly/test_requirements/requirements_38_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_38_optional.txt @@ -8,7 +8,7 @@ Pillow==8.2.0 pytest==6.2.3 pytz==2021.1 ipython[all]==7.22.0 -ipywidgets==7.6.3 +ipywidgets==8.0.2 ipykernel==5.5.3 jupyter==1.0.0 scipy==1.6.2 diff --git a/packages/python/plotly/test_requirements/requirements_39_optional.txt b/packages/python/plotly/test_requirements/requirements_39_optional.txt index 411c9c0f15..34b686ad02 100644 --- a/packages/python/plotly/test_requirements/requirements_39_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_39_optional.txt @@ -8,7 +8,7 @@ Pillow==8.2.0 pytest==6.2.3 pytz==2021.1 ipython[all]==7.22.0 -ipywidgets==7.6.3 +ipywidgets==8.0.2 ipykernel==5.5.3 jupyter==1.0.0 scipy==1.6.2 From 4f6201bb838abac3ffbd9d0498178eb927d99326 Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Thu, 20 Oct 2022 05:16:08 +0000 Subject: [PATCH 5/7] Set cell_number to 0 if history is not available --- packages/python/plotly/plotly/io/_base_renderers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index f4ccd0c0f8..5f42b2d01f 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -609,11 +609,14 @@ def to_mimebundle(self, fig_dict): def build_filename(self): ip = IPython.get_ipython() if IPython else None - cell_number = list(ip.history_manager.get_tail(1))[0][1] + 1 if ip else 0 - filename = "{dirname}/figure_{cell_number}.html".format( + if ip: + cell_number = next(ip.history_manager.get_tail(1), (0, -1, ""))[1] + 1 + else: + cell_number = 0 + + return "{dirname}/figure_{cell_number}.html".format( dirname=self.html_directory, cell_number=cell_number ) - return filename def build_url(self, filename): return filename From a7ce37fee02a676db18d02aa3c2ec5d0f0faaa35 Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Wed, 19 Oct 2022 17:04:29 -0700 Subject: [PATCH 6/7] Changelog entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d3cc37f9..4529ae9f7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## UNRELEASED + +### Updated + - Support for ipywidgets 8 [#3930](https://github.com/plotly/plotly.py/pull/3930) + ## [5.11.0] - 2022-10-27 ### Updated From 21bc09c5676d36e31e3129516cb63783b1279a8e Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Sun, 27 Nov 2022 22:57:09 -0800 Subject: [PATCH 7/7] Force use of application/vnd.jupyter.widget-view+json in BaseFigureWidget --- packages/python/plotly/plotly/basewidget.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/python/plotly/plotly/basewidget.py b/packages/python/plotly/plotly/basewidget.py index 0ecf2e97d3..1788466cfa 100644 --- a/packages/python/plotly/plotly/basewidget.py +++ b/packages/python/plotly/plotly/basewidget.py @@ -739,6 +739,18 @@ def _repr_html_(self): """ raise NotImplementedError # Prefer _repr_mimebundle_ + def _repr_mimebundle_(self, include=None, exclude=None, validate=True, **kwargs): + """ + Return mimebundle corresponding to default renderer. + """ + return { + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": self._model_id, + }, + } + def _ipython_display_(self): """ Handle rich display of figures in ipython contexts