Correct way to share multiple variables across callbacks


I have been attempting to get caching to work for my app as it requires a call to a time intensive function from several callbacks. The call to the function is based on the input of 10+ files, a combination of check boxes, drop-downs and input fields. In my app, I cannot seem to get the final graphing callbacks to fire.

I am using the caching example below as a template. This is a slightly modified version of what is posted in the docs. In the original example, a single value is passed between the callbacks and cached function. As far as I can tell, the best way to share many values is to return them as a list from the ‘primary’ called function. Is this correct, or is the a better way to do this so that the variables don’t have to be re-declared in the function?

Alternatively, if we could have multiple outputs from a single callback then these work arounds wouldn’t be needed in many cases ;). I know this is being worked on and should be released soon! Link

import os
import copy
import time
import datetime

import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import pandas as pd
from dash.dependencies import Input, Output
from flask_caching import Cache

external_stylesheets = [
    # Dash CSS
    # Loading screen CSS

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
    'CACHE_TYPE': 'filesystem',
cache = Cache()
cache.init_app(app.server, config=CACHE_CONFIG)

N = 100

df = pd.DataFrame({
    'category': (
        (['apples'] * 5 * N) +
        (['oranges'] * 10 * N) +
        (['figs'] * 20 * N) +
        (['pineapples'] * 15 * N)
df['x'] = np.random.randn(len(df['category']))
df['y'] = np.random.randn(len(df['category']))

app.layout = html.Div([
        options=[{'label': i, 'value': i} for i in df['category'].unique()],

        placeholder='input rate',


    # hidden signal value
    html.Div(id='signal', style={'display': 'none'})

# perform expensive computations in this "global store"
# these computations are cached in a globally available
# redis memory store which is available across processes
# and for all time.
def global_store(value,txtvalue):
    # simulate expensive query
    print('Computing value with {}'.format(value))
    df['x'] = df['x']*txtvalue
    return df[df['category'] == value]

def generate_figure(value, txtvalue,figure):
    fig = copy.deepcopy(figure)
    filtered_dataframe = global_store(value,txtvalue)
    fig['data'][0]['x'] = filtered_dataframe['x']
    fig['data'][0]['y'] = filtered_dataframe['y']
    fig['layout'] = {'margin': {'l': 20, 'r': 10, 'b': 20, 't': 10}}
    return fig

@app.callback(Output('signal', 'children'), [Input('dropdown', 'value'), Input('txtinput','value')])
def compute_value(value,txtvalue):
    # compute value and send a signal when done
    return [value,txtvalue]

@app.callback(Output('graph-3', 'figure'), [Input('signal', 'children')])
def update_graph_3(return_list):
    return generate_figure(value, txtvalue,{
        'data': [{
            'type': 'histogram2d',

if __name__ == '__main__':