I am trying to employ a data generator inside a callback of a dash app. The idea is to plot some values which are being updated within a data generator function. The generator is created using yield and my question is that how can I employ the generator in an correct way in dash applications. Here are some information that might be helpful for more clarification:
I am a newbie to Dash Plotly - but I recently created an example with an animated graph which updates once a second.
I had similar errors when the format of the data I was returning was not quite what Dash was expecting…
Feel free to check my code in case it helps…
Thanks for the update - but I am not sure those are the takeaways I was intending to share. My issue was the actual content of the ‘data’ variable was not correct and I got the same error as you. If, however, you have been able to successfully plot your chart outside the callback with the same data - then this is not the same issue for you.
In terms of your other points - as I am also a DASH Newbie not sure how accurate the following points may be…
My get_data takes less than the 1s interval - so I don’t have the same issue you are potentially faced with.
I am also fairly new to Python but my guess is that if the generator is running on the same thread as the callback, it would not be possible for the callback to trigger again as your generator call is still tieing up the callback thread?
I guess a dirty/hack way could be to use a global variable which is set and unset by your generator to indicate when it is still generating and check for that at the start of the callback and return if set, and thereby avoiding another call to the generator?