Skip to content

Commit

Permalink
More compatibility fixes for plotly 6.0 (#7682)
Browse files Browse the repository at this point in the history
* More compatibility fixes for plotly 6.0

* Cast to array

* Ensure we patch FigureWidget
  • Loading branch information
philippjfr authored Jan 31, 2025
1 parent d8577f4 commit 08e5115
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions panel/models/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from bokeh.events import ModelEvent
from bokeh.models import ColumnDataSource, LayoutDOM

from ..io.resources import JS_URLS, bundled_files
from ..config import config
from ..io.resources import bundled_files
from ..util import classproperty

PLOTLY_VERSION = '2.35.3'
PLOTLY_VERSION = '3.0.0'


class PlotlyEvent(ModelEvent):
Expand All @@ -28,15 +29,14 @@ class PlotlyPlot(LayoutDOM):
a bokeh plot.
"""
__css_raw__ = [
"https://api.mapbox.com/mapbox-gl-js/v3.0.1/mapbox-gl.css",
f"{config.npm_cdn}/maplibre-gl@4.4.1/dist/maplibre-gl.css"
]

@classproperty
def __css__(cls):
return bundled_files(cls, 'css')

__javascript_raw__ = [
JS_URLS['jQuery'],
f'https://cdn.plot.ly/plotly-{PLOTLY_VERSION}.min.js'
]

Expand Down
9 changes: 6 additions & 3 deletions panel/pane/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from bokeh.models import ColumnDataSource
from pyviz_comms import JupyterComm

from ..util import lazy_load
from ..util import lazy_load, try_datetime64_to_datetime
from ..util.checks import datetime_types, isdatetime
from ..viewable import Layoutable
from .base import ModelPane
Expand Down Expand Up @@ -156,7 +156,7 @@ def _get_sources_for_trace(json, data, parent_path=''):
def _update_figure(self):
import plotly.graph_objs as go

if (self.object is None or type(self.object) not in (go.Figure, go.FigureWidget) or
if (self.object is None or not isinstance(self.object, (go.Figure, go.FigureWidget)) or
self.object is self._figure or not self.link_figure):
return

Expand Down Expand Up @@ -257,7 +257,10 @@ def _convert_trace(trace):
continue
arr = trace[key]
if isinstance(arr, np.ndarray):
arr = arr.astype(str)
if arr.dtype.kind == 'M' and arr.ndim == 2 and arr.shape[1] == 1:
arr = np.array([[str(try_datetime64_to_datetime(v[0]))] for v in arr])
else:
arr = arr.astype(str)
elif isinstance(arr, datetime_types):
arr = str(arr)
else:
Expand Down
2 changes: 1 addition & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ holoviews = ">=1.16.0"
jupyterlab = "*"
matplotlib-base = "*"
pillow = "*"
plotly = ">=4.0"
plotly = ">=6.0"
# Optional dependencies - dev
watchfiles = "*"
# Test dependencies
Expand Down

0 comments on commit 08e5115

Please sign in to comment.