I am using a hidden div to store computationally expensive intermediate data that is calculated when a new file is uploaded. That seems to work OK. My problem is that I need to update graphs based on drop-down values that indicate subsets of my Pandas dataframe. When I choose a dropdown value, the entire dataset has to be loaded, subsetted, and then graph updated. I have two problems with this setup:
- From the time I choose a value in the drop-down, to the time the
update_graphfunction runs, is on the order of 5-10 seconds (i.e. I don’t see the
Updating graph!statement in my console until 5-10 seconds after I choose a drop-down value.
- It takes a LONG time to do json.loads(dataset) and then subset the data.
There must be a better way to do this? This is how it is setup now:
@app.callback(Output('My Graph', 'figure'), [Input('Dropdown', 'value')], [State('intermediate-data', 'children')]) def update_graph(dropdown, datasets): print("Updating graph!") if datasets is not None and dropdown is not None: datasets = json.loads(datasets['dataA']) data = pd.read_json(datasets['dataA'], orient='records') data = data[data['subset_column'].isin(dropdown)] graph, f = update_graph_function(data) return f else: raise PreventUpdate