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.