[Solved] Using a long interval, render once before interval starts

Hello All,

Quick question about live updates. I used the example at https://plot.ly/dash/live-updates to build the following app (on heroku): https://safe-island-13543.herokuapp.com. I set the interval to 5 seconds, but then it takes 5 seconds for the graph to render the first time. The data in my database gets updated every 15 minutes, so there is no reason to use such a short interval. Does anyone have an example of this I could follow?



Ignore me.

Just use your figure generation function in dcc.Graph, e.g:

app.layout = html.Div(children = [
        id = 'whatever',             
        figure = generate_figure()     
        id = 'interval-component',     
        interval = 5 * 1000            

Classic ask the question and instantly realize you can solve it yourself :stuck_out_tongue:

I was having the same issue, thanks for the solution.

One problem though: I can’t have a callback on the generate_figure function. Currently, I just write the same function two times, once with the callback and once without. Is there some cleaner workaround for that?

It’s hard to say without seeing a reproducable code snippet, but perhaps you can do something like:

def generate_figure():
    return figure

app.layout = generate_figure()


Instead of @app.callback. For more about how the @ works in the @app.callback signature and how you can get around it, see this explanation on decorators: python - How do I make function decorators and chain them together? - Stack Overflow