Skip to content

Commit 509faa9

Browse files
Improve the update mechanism for ui.plotly (#4317)
This PR tries to solve #4186 by calling the `update()` method in JavaScript explicitly rather than within the `updated` hook. It seems to resolve the problem described with the following code snippet: ```py ui.label('1. Manually zoom the plot') ui.button('2. Update the label', on_click=lambda: label.set_text(label.text + '.')) ui.button('3. Update the plot', on_click=lambda: plot.update()) ui.label('4. --> The plot resets unexpectedly') label = ui.label('...') plot = ui.plotly({'layout': {'uirevision': 'constant'}}) ``` Tests are passing and demos seem to work like before.
1 parent 5b42401 commit 509faa9

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

nicegui/elements/plotly.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def update_figure(self, figure: Union[Dict, go.Figure]):
4646
def update(self) -> None:
4747
self._props['options'] = self._get_figure_json()
4848
super().update()
49+
self.run_method('update')
4950

5051
def _get_figure_json(self) -> Dict:
5152
if isinstance(self.figure, go.Figure):

nicegui/elements/plotly.vue

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ export default {
88
await import("plotly");
99
this.update();
1010
},
11-
updated() {
12-
this.update();
13-
},
1411
methods: {
1512
update() {
1613
// wait for plotly to be loaded

0 commit comments

Comments
 (0)