Saving/serializing a Dash app

Hi,

I’ve written a Dash app for data review. The users supply the input data files and the app is automatically created for them. However creating it takes a while, since the amount of data is large and the app consists of dozens of Plotly plots.

Since the same datasets are reviewed again and again, I was wondering if it’s possible to serialize the entire Dash app and save it to disk? I’ve tried using dill, but dill.dump complains about dash.resources.config not being accessible under that name.

Serializing the Plotly plots is possible, but it would be more elegant to serialize the entire app.

I’m guessing you want to do this because you don’t want to make the user upload data every time they use the app, so you want to save the state of the upload component.

So, do you need to serialize the entire Dash app? Or do you just need to save the data that’s been uploaded, create some kind of reference index of everything that has been saved, and load it when needed based on which user is active? My feeling is that serializing the entire app is overkill.

I usually store very specific and usually really heavy data as a pickle file with a hash name that i pull every time the user enters the same parameters this way when the user load the page its only a matter of how much the components take to load

Thanks for the replies guys. To clarify for @russellthehippo, there’s no upload component. Rather, the data files are selected by the user prior to the creation of the app. Building the app takes several minutes on a slow laptop; at least 90% of the time is spent creating various Plotly graphs.

As @lahashh suggested, I’ve been thinking of creating an MD5 digest of all the input files and then loading saved Plotly graphs if they exist and digest matches. However, serializing and saving the entire app would require significantly less code. I’m also just curious to know why serialization of the Dash app does not work (maybe dynamically created classes?)

I honestly don’t think its possible to save a dash page in the python code maybe if the app is embedded in another web page you can store the final rendered page. I have a few questions Can you be more specific on how and why are you building your apps locally instead of a server?? How big are your files to take that long? When testing in my machine (not the best laptop of all :smile: ) the apps load really quick so maybe it’s not a thing of the javascript components loading slowly but instead of data processing. If that’s the case techniques of pre processing data and storing final data in pickle files may help.

Thanks for the clarification, makes more sense. It seems that creating the figures is the problem then, so you need to simply serialize the figure objects.

I currently do a version of this using on-disk serialization as a kind of caching: I pickle a dictionary on disk of all the figures that have been generated. Then when the inputs match something that’s been generated before, I simply read the figure dictionary from disk and return the figure that matches the inputs. If the figure hasn’t been created before, it creates the figure and adds it to the figure dictionary for next time.

You can do a perfectly threadsafe version of this using index files or a SQLite table with filenames matched with the inputs.

2 Likes

I use a similar solution to the one provided by @russellthehippo with a no sql database (since my data is alocated there) no problems so far

1 Like