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

Internal state variable

Hi,

First I quickly want to say that this is a great project, exactly what I was looking for!

I am making a display with multiple pages (like dash-doc with the radio-buttons for chapters) and I want to share states between the pages (like a a page to select filters and a graph page). For now I have added self.states = {} to the Dash class, but this does not work when multiple people are using the dashboard since this variable is shared. I would probably need to store it on the client side, does anybody have any recommendations for this?

You can find my current code here.

Bart

Sharing state on the backend isn’t possible right now. Dash apps are meant to be run on multiple processes where there isn’t access to common memory. Stateful backends also make it multi-user sessions harder to reason about.

Could you go into a little bit more detail about what you’d like to share between pages? A simple code example would be helpful here. Thanks!

I am creating lots of hidden dummy dropdowns to store “state” - It works well.
You can then access them in callbacks using State(), instead of Input(). Otherwise you most likely create cycle dependancies.

1 Like

So using an internal state variable is a bad idea for a few reasons. Right now I am figuring out how to use sessions or cookies to store that information, so it is all client dependent. But I haven’t figured out how to exactly implement that with Dash.

I am making a display with multiple pages (like dash-doc with the radio-buttons for chapters) and I want to share states between the pages

I just added two new components that might help out with the multi-page pattern. See https://github.com/plotly/dash/issues/77 for some more details.

You could also maybe do something like display a div and set children to be json.dumps(your_state).