Storing python dictionnary of DataFrames

Hello everyone,

I am currently facing an issue regarding “caching” some data into my dash application.
The data that I need to store within my application is currently in the form of: a dictionary of pandas DataFrames.
Here is a description of what it looks like:

data = {"BLOCK1": {"DATA": pd.DataFrame()},
        "BLOCK2": {"DATA": pd.DataFrame()},
         ...,
        "BLOCKn": {"DATA": pd.DataFrame()}
}

These data come from a custom python class that I made, handling all the computationally expensive steps. It is instantiated from an initial callback from the user selecting an input file from a drop-down list. Therefore, I do not know ahead what the data shape will be (how many blocks, and what columns in the different DataFrame(s) there will be.)
The general idea of my application is as follows:

1: User selects a file name from a drop-down menu
A: This triggers my custom python class to cache the data
B: Generates some default plots

2: User selects a date range from a calendar:
A: Updates the plots from 1.B by accessing the data cached in 1.A

My question is, how can I store such a data-structure in dash. I have looked at dcc.Store but the complete JSON data structure does not seem suitable for what I want to do.

Any thoughts about where I could start?

Thank you very much for your time and help.

R3s0luti0n

Hi @R3s0luti0n

See if the server side callback could help your goal, its a dcc.Store that do not need to convert the data into JSON elements.

Hi @Eduardo,

Thank you for your answer. I have had a look at it and it seems that the dash_extensions.callback is deprecated and has been removed from dash_extensions new version version: 0.0.60.
Maybe I missed something in the new documentation that could still do the job?

I think it’s included in the new Dash version.

I’m sure @Emil will give you the rigtht answer as soon as he recieves this message. :smiley:

1 Like

How does your implementation look? Did you follow the docs?

Hi @Emil,

I currently do not have an implementation as I am completely lost with the dash library structure. It seems that I am supposed to use the ServersideOutput module which I can’t find anywhere.
When trying to import it from enrich I get the following:

> ImportError: cannot import name 'ServersideOutput' from 'enrich' (/usr/lib/python3.9/site-packages/enrich/__init__.py)

Has this been implemented somewhere else under a different name?
Sorry to sound stupid here but I simply do not understand it.

R3s0luti0n

There is a complete example in the examples folder,

2 Likes

Thank you for the guidance.

EDIT

I deleted my original reply as I spotted some terrible mistakes in my code.
Everything is working fine now.

Thank you very much for your time and help!

/R3s0luti0n

1 Like