Live Updating Components

The dccInterval Component

Components in Dash usually update through user interaction like selecting a dropdown, dragging a slider, or hovering over points.

If you're building an application for monitoring, you may want to update components in your application every few seconds or minutes.

The dccInterval element allows you to update components on a predefined interval. The n_intervals property is an integer that is automatically incremented every time interval milliseconds pass. You can listen to this variable inside your app's callback to fire the callback on a predefined interval.

This example pulls data from live satellite feeds and updates the graph and the text every second.

Sign up for Dash Club → Two free cheat sheets plus updates from Chris Parmer and Adam Schroeder delivered to your inbox every two months. Includes tips and tricks, community apps, and deep dives into the Dash architecture. Join now.

Updates on Page Load

By default, Dash apps store the app.layout in memory. This ensures that the layout is only computed once, when the app starts.

If you set app.layout to a function, then you can serve a dynamic layout on every page load.

For example, if your app.layout looked like this:

then your app would display the time when the app was started.

If you change this to a function, then a new datetime will get computed everytime you refresh the page. Give it a try:

Heads up! You need to write app.layout = serve_layout not app.layout = serve_layout(). That is, define app.layout to the actual function instance.

You can combine this with time-expiring caching and serve a unique layout every hour or every day and serve the computed layout from memory in between.