Black Lives Matter. Please consider donating to Black Girls Code today.

On-click event bar-chart - AttributeError: 'FigureWeidget' object has no attribute 'on_click'

Hi all,

I have been looking all over the web for help, but to no avail, so now I am trying here.

My goal is to have a bar chart where I can click on a bar which will then interact with a line chart and show line chart data corresponding to that bars category.

I tried to start from a simple example such as the one proposed here: Interactive Graph Click Event by jmmease, but when I run his code-snippet I get the following error: AttributeError: ‘FigureWidget’ object has no attribute ‘on_click’.

I am a little lost in all the documentation and hope that you could help me in the right direction with:

a) How I solve the error
b) How I might achieve my goal of the interactive graphs.

PS. I am working in Jupyter Notebook and need to keep all interactivity there. The notebook will be shared using Voila as a web-application.

Hi @miqlliot,

the on_click method applies to a trace, not to a FigureWidget object.

try this:

import plotly.graph_objs as go
from ipywidgets import Output, VBox

fig = go.FigureWidget()
fig.add_pie(values=[1, 2, 3])
pie = fig.data[0]

out = Output()
@out.capture(clear_output=True)
def handle_click(trace, points, state):
    print(points.point_inds)

pie.on_click(handle_click)

VBox([fig, out])