Using a generator to update Graph

I want to read a updated log file and update my Graph component in real time. If I just use “n_intervals” component, this means that the callback function must be run each time, the log file is loaded and the data is read
repeatedly. What’s more each update will change the zoom setting of Graph component

I know some examples that update the Graph in the Dash Tutorial and “extendData” keyword. But these example just add the given data (like a list of data given globally) to the Graph which is different from the real case reading from a log file.

So I want to use a Python generator according to the comments as https://stackoverflow.com/questions/5419888/reading-from-a-frequently-updated-file to just read the updated part of log file. But it’s hard to design a way to realize it.

There are some challenges:

  1. obviously we can not put the python generator in the updated callback function (because the callback function will be executed repeatedly and the “open” function in a generator will be executed repeatedly and the file will be closed after each “callback” function is closed. It will cause the generator not working)
  2. when write the generator in “main” function, the file path will be chosen in layout, I don’t know how to get the chosen “drop down” information in the main function.

I hope your help :slight_smile:

Did u manage to find a solution, having the same issue and need to employ a costume data generator inside a callback.
Thanks in advance,