Hello
The example code is below. Please run it in Jupyter Labs. I have a selector and a figure. I change the selector → FigureWidget is updated. However, it flickers. How to make it update without flickering? I try with.fig.batch_update() but it does not have any effect?
Thanks!
import ipywidgets as widgets
import plotly.graph_objects as go
import numpy as np
# update
def update_function(fig, symbol):
fig.data = [] # remove all Trace
Categories = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
with fig.batch_update():
for name in Categories:
fig.add_trace(go.Violin(y=np.random.normal(np.random.randint(0,10),1,100), name=name, box_visible=True) )
def func_change(change):
if change['type'] == 'change' and change['name'] == 'value':
update_function(fig, selector_choice.value)
pass
all_choices = ['CHOICE_1', 'CHOICE_2', 'CHOICE_3']
selector_choice = widgets.Dropdown(
options=all_choices,
value=all_choices[0],
description='Choice\n:',
)
selector_choice.observe(func_change)
fig = go.FigureWidget()
update_function(fig, all_choices[0]) # make sure we see something
widgets.VBox([selector_choice, fig])