Hi,
I need to create a real-time dashboard that displays the latest minute of MQTT data from several devices, updated every 100ms.
I’ve created a multi-page Dash application with a page for each device or process. I used the dash_mqtt
component to subscribe to my topic on each page, with an extendData
Output
to display my live changes on my plotly charts.
Unfortunately, I have a problem because if I switch to page 2 with device #2, my subscription will restart from that point (another dash_mqtt
component) and I won’t have the previous 1 minute of data for device #2.
What I would like is to have page 1 display real-time (last 600 points) data from device #1, switch to another page to see another device, and have my 600 points served.
To achieve this, I thought of two methods:
- Having a
dash_mqtt
component on my main page (always up) writing to adcc.Store
component. Each page will have access to this maindcc.Store
component and pick the last 600 points of their device every 100ms with adcc.Interval
component. However, this method could be resource-intensive because all the MQTT traffic is going to be sent directly to my client, along with parallel requests from thedcc.Interval
. - Having the server execute a Background Callback at start and silently subscribe to the MQTT topics with the regular
paho mqtt
library. It could put the data (last 600 points of all devices) in its Disk Cache, and the client would ask for their device’s data with adcc.Interval
component. Alternatively, the data could be stored in adcc.Store()
on the main page, and the client could fetch the data from there. However, this method will create extra traffic, but sending the data to thedcc.Store()
in batches could help mitigate this.
Do you think either of these propositions is viable and scalable, or would you recommend something else?
Thanks in advance.