Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

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.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'})

    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)

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

    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).