✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Server side persistence

Hi there,

I have a question about dash persistence. As far I understand it from reading the docs, memory, local and session, the persistence types, are all client side persistence types. So let’s say I’ve a datatable, if i make changes to this datatble and the persistence is set to local, then these changes will be saved for each session i log into the app, correct?

But these changes will only persist on the machine that I would’ve used the previous time. The way I’m understanding it is that if I were to log into the app on another machine, this updated datatable will not exist there since the updates only persisted in the local memory of the previous machine. How do I make the changes to my datatable, and all my props for that matter, persist across the server? How do i design my app such that a user who logs into the app from any machine will see the last updated data from the previous user?

One approach would be to store the datatable parameters within a server-side database. You can use Redis to store the parameters and then check/apply those parameters when the datatable is loaded. This was my initial approach for a project until I realized that the “persistence” option existed. As you noted, those are only available locally though, which was fine for my project.

If it’s not too much trouble, can you please explain to me how i’d do that? I don’t have that much experience with redis.

The high-level approach would be…

  1. Install Redis (Requires Linux)
  2. Install redis-py
  3. Create a Dash callback that stores the datatable parameters as they change.
  4. Restore the datatable parameters when Dash loads

Redis is a key:value database, so you could store the parameter values for specific users or groups. When that specific user or group loads Dash, it could retrieve the last known parameters based on their login. If there are no users or groups, then there would just be a generic key:value for all users.

Here’s a couple resources with sample applications to get started. You may want to work with it directly through command-line to get a feel for it first though. In other words, just setting, getting, persisting, and expiring keys:values.

So i’ve been playing around with redis (& flask caching and mongodb) to persist my app. Thank you so much for this idea.

Fantastic! I’m glad you discovered flask-caching, as I forgot to mention that. I’ve been using flask-session with Redis as well, which lets sercer-side sessions persist across app servers. Just another great tool if you ever need it.