Black Lives Matter. Please consider donating to Black Girls Code today.

Live updates with Dash on Heroku

Hey All,

Has anyone tried to deploy an app on Heroku which uses “Live Updates”?

I deployed the following https://github.com/barrymoo/crc-status-dash on heroku https://safe-island-13543.herokuapp.com, but it gets frozen in time. In the heroku logs, I see:

2017-08-18T20:33:27.371486+00:00 heroku[router]: at=info method=POST path="/_dash-update-component" host=safe-island-13543.herokuapp.com

However, it doesn’t actually update on screen. The title says “Updating…” and the plot remains the same. Eventually, I get heroku[web.1]: Idling and the app spins down. This could be Heroku protecting from people keeping apps running all the time, but I wanted to ask here first.

Thanks!

Barry

1 Like

We have an example with live updates here: https://plot.ly/dash/gallery/live-wind-data/

Briefly looking at your code, it looks like you might be missing

server.secret_key = os.environ.get('SECRET_KEY', 'my-secret-key')

Let us know if that works!

Yep, that was it. I removed it while I was building the thing initially and never put it back. Why do I not need this locally?

Very close, when I navigate to https://safe-island-13543.herokuapp.com it always shows the newest available time as 8/21/17-13:15 and 5 minutes later it will update with the correct information. Any thoughts?

I think it’s a heroku specific thing

Purge your browser cache? Works for me.

Purging the cache didn’t do anything. The only way you can get an up to date screen when you open the app:

  1. The dyno spins down due to inactivity and you revisit
  2. You manually restart the dyno

So what you wrote here confused me. I can now confirm that when I navigate to the app, the most recent time it displays is some previous time and not the most recent one. Sounds like your functions are not being fire when you first

One difference I note between the wind app and yours is that you assigned the generate functions as children to your graphs, but I don’t see how that should affect anything

app.layout = html.Div(children = [
        html.H1(children = 'CRC Status'),
        dcc.Graph(
            id = 'crc-graph',
            figure = generate_figure()
        ),
        html.Table(
            id = 'crc-table',
            children = generate_table(),
        ),
        dcc.Interval(
            id = 'interval-component',
            interval = 5 * 60 * 1000
        )
    ]
)

So what you wrote here confused me.

Sorry, I should have been more clear. I was trying to narrow down the issue on the fly.

One difference I note between the wind app and yours is that you assigned the generate functions as children to your graphs, but I don’t see how that should affect anything

If I don’t do this my layout won’t contain anything until the first interval ticks. Because I don’t need, or want, a short interval, this is problematic. I can also confirm that this behavior isn’t Heroku specific. It happens when I run the app locally too (although it was less obvious because I was restarting the server as I was making changes).

I haven’t poked around in the code at all, but is it possible to get the interval to tick once when someone navigates to the app?

You can do this by setting app.layout to be a function that returns a See https://plot.ly/dash/live-updates for more details.

This is working, thanks so much. Did you add that over the course of this ticket, or am I just blind?

It has been available since the launch :slight_smile:

1 Like

Thanks for your help! This is a lot nicer than my previous version using just plotly.

1 Like