Hi so I was following one of the tutorials for Dash and the tutor used “events” to update the plot live with intervals.
But in the newest version of Dash events are removed so I wonder how I could rewrite the code some it would be still working:
You should use the n_intervals prop of graph-update as an input to your callback. As the name suggests, n_intervals keeps count of how many times the interval has fired, and so each time the interval fires, n_intervals gets incremented which triggers your callback. The only change you have to make to the callback is to an argument to receive n_intervals, which you can then ignore in the function body.
@app.callback(
Output("graphs", "children"),
[Input("vehicle-data-name", "value"), Input("graph-update", "n_intervals")]
)
def update_graph(data_names, n):
# rest of function is the same
Oh that’s strange. It does work though with the events and an earlier version of Dash? What happens instead, when you test on Dash 0.39 or later? Do you get an error or just no updates?
There is actually a small problem with the snippet you posted, you have an unmatched square bracket. Is that in your code or just in your post?
I managed to get your code to run (after changing Event to Input) by adjusting the rate at which the Interval fires, namely by changing interval=100 to interval=200. I’m not 100% what’s going on, but it seems like the interval was firing faster than the callbacks could be run, and nothing was getting rendered as a result. Even with the change to interval=200, it doesn’t look to me like the graphs are getting updated 5 times a second.
Part of this might be the animation when the graph gets updated? You could look into either disabling that or adjusting the length of the animation.