Everything on my front end freezes, including interval updates, while I’m inside a function call.
To be specific, I got a front end rocking some graphs and charts and a time consuming function that crunches some numbers and returns a result. I would like to show intermediate results of the timely function on a graph on the front end as the function is running. I was thinking the function could write the intermediate results to a list in shared memory, and the front end could be continuously pinging that list on interval to draw chart.
Any ideas thanks a tun everyone!
By default, Dash runs on a single process so long-running functions will block any other requests from being processed. Your app can handle multiple requests in parallel by using threads, multiple processes, or multiple workers. Here are some options:
server = app.server
and then run in terminal with:
$ gunicorn --workers 4 app:server
app refers to a file named
server is the variable as defined above.
Thank you Chris, option 1 works for my situation fantastically. It’s worth mentioning that I also needed to make my ‘return’ function into a ‘yield’ function in order to get those intermediate results out of the function and into dash for plotting.
While we are on the subject; would it be possible to make a yield from a function trigger an update to a chart element in dash? Instead of having it run on an interval and refresh the chart even if there is no new data. I was thinking I could have a work around for this by having some kind of binary trigger variable which checks each interval if there is new data and if and only if true, then update graph. But, maybe there is an easier way?
That would be the way to do it right now - you can raise an exception inside a callback to prevent the update from propogating to the client.
Thanks Chris, you’re a rockstar. Great product.