Callbacks not working while sharing data

Hi- I have tried to copy the format of example 1 in the tutorial to share data between callbacks. In short, I am storing a dictionary and then trying to update the page title and a dropdown menu. My code is as follows:

app.layout = html.Div([
    html.H1(id='header1'),
    dcc.Markdown(markdown_text),
    html.Label('Enter Activity #'),
    dcc.Input(id='input-box', value=1898, type='text'),
    html.Button('Submit', id='button1', type='submit'),
    dcc.Dropdown(id='dropdown1', multi=True, placeholder="some text"),
    html.Div(id='intermediate-value', style={'display': 'none'})
])


@app.callback(
    Output('intermediate-value', 'children'),
    [],
    [State('input-box', 'value')],
    [Event('button1', 'click')])
def store_meta(act_num):
    #this is making a SQL query from another script and works fine
    general = ActFig(act_num)
    meta = general.pull_meta()
    return json.dumps(meta)


@app.callback(
    Output('header1', 'children'),
    [Input('intermediate-value', 'children')])
def title_maker(data):
    if data is not None:
        meta = json.loads(data)
        return meta['title']


@app.callback(
    Output('dropdown1', 'options'),
    [Input('intermediate-value', 'children')])
def fig_options(data):
    if data is not None:
        meta2 = json.loads(data)
        return meta2['build']

If I get rid of the second callback function ā€œfig_optionsā€ it updates the page title correctly. However, if I include the second callback function, neither callback works. Would love any tips! I have been stuck on this, changing states/inputs, etc. for hours. If I get rid of the ā€˜is not Noneā€™, the code works as expected but I get TypeErrors- why would ā€˜is not Noneā€™ break it?

Likewise, if I remove the ā€˜is not Noneā€™ and then add a third callback that uses the Dropdown as an input, nothing works.

I donā€™t have time to go through your example right now, but one quick thing to note: Events have recently been removed from Dash, so youā€™ll want to remove the Event from your store_meta callback and instead use the n_clicks property as an Input.

1 Like

Ok! Didnā€™t know that! Super helpful

Just tried this- and in this way, the button is always ā€˜clickedā€™ as part of the initial callbacks (and thereafter)- whereas when you use ā€˜clickā€™ as an event, it waits to load until the actual first click (and clicks thereafter).