I try to create a stacked bar chart; if I click at a bar, it will show the contents. My code only works for one layer. Can anyone help?
drill down to 2-level bar chart
import plotly.graph_objects as go
import plotly.graph_objects as px
from ipywidgets import Output, VBox
x = [‘LA’, ‘Chicago’, ‘Phoenix’, ‘Madison’]
plot = px.FigureWidget(data=[go.Bar(
name = ‘ICE Cars’,
x = x,
y = [100, 200, 500, 673]
),
go.Bar(
name = ‘EVs’,
x = x,
y = [56, 123, 982, 213]
)
])
barplot0 = plot.data[0]
barplot1 = plot.data[1]
plot.update_layout(barmode=‘stack’)
plot.show()
create our callback function
out = Output()
@out.capture(clear_output=True)
def update_point(trace, points, selector):
c = list(barplot.marker.color)
print(points)
for i in points.point_inds:
c[i] = ‘#bae2be’
with f.batch_update():
barplot.marker.color = c
#barplot0.on_click(update_point)
barplot1.on_click(update_point)
VBox([plot, out])