diff --git a/panel/pane/plotly.py b/panel/pane/plotly.py index b1d35ac90c..b4eb7f0861 100644 --- a/panel/pane/plotly.py +++ b/panel/pane/plotly.py @@ -45,7 +45,7 @@ class Plotly(PaneBase): * "mouseup": updates are synchronized when mouse button is released after panning * "continuous": updates are synchronized continually while panning - * "throttle": updates are synchronized while panning, at + * "throttle": updates are synchronized while panning, at intervals determined by the viewport_update_throttle parameter """, objects=["mouseup", "continuous", "throttle"]) @@ -150,7 +150,14 @@ def _update_figure_style(self): def _update_figure_layout(self): if self._figure is None or self.relayout_data is None: return - self._figure.plotly_relayout(self.relayout_data) + relayout_data = self._clean_relayout_data(self.relayout_data) + self._figure.plotly_relayout(relayout_data) + + @staticmethod + def _clean_relayout_data(relayout_data): + return { + key: val for key, val in relayout_data.items() if not key.endswith("._derived") + } def _send_update_msg( self, restyle_data, relayout_data, trace_indexes=None, source_view_id=None @@ -210,7 +217,7 @@ def _plotly_json_wrapper(fig): if isdatetime(data[idx][key]): arr = data[idx][key] if isinstance(arr, np.ndarray): - arr = arr.astype(str) + arr = arr.astype(str) else: arr = [str(v) for v in arr] data[idx][key] = arr diff --git a/panel/tests/pane/test_plotly.py b/panel/tests/pane/test_plotly.py index 5c56eeecfa..85e00b5eb3 100644 --- a/panel/tests/pane/test_plotly.py +++ b/panel/tests/pane/test_plotly.py @@ -165,7 +165,7 @@ def test_plotly_pane_numpy_to_cds_traces(document, comm): @plotly_available def test_plotly_autosize(document, comm): trace = go.Scatter(x=[0, 1], y=[2, 3]) - + pane = Plotly(dict(data=[trace], layout={'autosize': True})) model = pane.get_root(document, comm=comm) @@ -187,7 +187,7 @@ def test_plotly_autosize(document, comm): @plotly_available def test_plotly_tabs(document, comm): trace = go.Scatter(x=[0, 1], y=[2, 3]) - + pane1 = Plotly(dict(data=[trace], layout={'autosize': True})) pane2 = Plotly(dict(data=[trace], layout={'autosize': True})) @@ -207,7 +207,31 @@ def test_plotly_tabs(document, comm): assert not model2.visible assert cb2.args['model'] is model2 assert cb2.code == 'model.visible = (cb_obj.active == 1);' - + tabs.insert(0, 'Blah') assert cb1.code == 'model.visible = (cb_obj.active == 1);' assert cb2.code == 'model.visible = (cb_obj.active == 2);' + +@plotly_available +def test_clean_relayout_data(): + relayout_data = { + "mapbox.center": {"lon": -73.59183434290809, "lat": 45.52341668343991}, + "mapbox.zoom": 10, + "mapbox.bearing": 0, + "mapbox.pitch": 0, + "mapbox._derived": { + "coordinates": [ + [-73.92279747767401, 45.597934047192865], + [-73.26087120814279, 45.597934047192865], + [-73.26087120814279, 45.44880048640681], + [-73.92279747767401, 45.44880048640681], + ] + }, + } + result = Plotly._clean_relayout_data(relayout_data) + assert result == { + "mapbox.center": {"lon": -73.59183434290809, "lat": 45.52341668343991}, + "mapbox.zoom": 10, + "mapbox.bearing": 0, + "mapbox.pitch": 0, + } \ No newline at end of file