How to get plotly to work with ipywidgets

The plotly interactive example with ipywidgets,

has not been updated to the latest version of plotly. I’ve gotten the code to work by migrating the code to use go.Histogram:

traces = []
trace = go.Histogram(x = x1, opacity = 0.75, name = 'Arrival Delays', )
traces.append(trace)

trace = go.Histogram(x = x2, opacity = 0.75, name = 'Departure Delays')
traces.append(trace)

layout = go.Layout(barmode = 'overlay', title = 'Delays (All)', 
                   xaxis = dict(title = 'Delay in Minutes', titlefont = dict(size = 18, color='#7f7f7f')),
                   yaxis = dict(title = 'Number of Delays', titlefont = dict(size = 18, color='#7f7f7f')))

fig = go.Figure(data = traces, layout = layout)

and updating the traces in response() with:

            fig.update_traces(patch = dict(x = x1), selector = dict(name = 'Arrival Delays'))
            fig.update_traces(patch = dict(x = x2), selector = dict(name = 'Departure Delays'))

However, when I change the airline, airport, or month, the histogram does not get redrawn, and thus, it really doesn’t update. I verified that the callbacks, validate() and response() are getting called, and my new code is being executed, when a change is made. I’ve tried calling fig.show() and display(fig) after updating the traces, but the histrogram does not update; instead another histrogram is drawn BELOW and AFTER the first rendering of the histogram, not in place.

Can someone tell me what I need to do to truly update the histogram interactively?

Thank you.

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online