I thought I understood Inputs and callbacks, but every time I think I have it there’s something else lol.
I had this callback that worked great with no errors. It’s on a page called graph.py in a pages directory.
@callback(
Output('store-results', 'data'),
Input('save', 'n_clicks'),
State('store', 'data'),
State('new-start-date', 'value'),
State('offset-checkbox', 'value'),
State('offset-number', 'value'),
State('lower-bound', 'value'),
State('upper-bound', 'value'),
State('selections', 'data')
)
def create_df_from_inputs(
n1,
original_store,
new_start_date,
offset_check,
offset_custom,
lower_bound,
upper_bound,
events):
if n1:
logging.info('Saving Information to POD')
if original_store['df'] != []:
df = pd.DataFrame(original_store['df'])
engine_name = df.iloc[0, 1]
df['SavGol'] = signal.savgol_filter(df['deviation'], 576, 1)
if new_start_date is None:
new_start_date = df.iloc[0, 2]
logging.info(f'New Start Date: {new_start_date}')
end_date = df.iloc[-1, 2]
logging.info(f'End Date: {end_date}')
offset = 0
if offset_check:
offset = df.loc[0, 'SavGol']
logging.info(f'Offset: {offset}')
if offset_custom:
offset = offset_custom
logging.info(f'Offset: {offset}')
store = {
"report": original_store['report'],
"engine": engine_name,
"new_start_date": new_start_date,
"end_date": end_date,
"offset_value": offset or None,
"lower_bound": lower_bound or None,
"upper_bound": upper_bound or None,
"events": events,
}
return store
However I realized I wasn’t gathering the data I intended. So I created a third dcc.Store on my app.py (not in pages) and adjusted the callback to this:
# Save Input Information
@callback(
Output('store-results', 'data'),
Input('save', 'n_clicks'),
State('store', 'data'),
State('offset-store', 'data'),
State('new-start-date', 'value'),
State('lower-bound', 'value'),
State('upper-bound', 'value'),
State('selections', 'data'),
)
def create_df_from_inputs(
n1,
original_store,
offset,
new_start_date,
lower_bound,
upper_bound,
events,):
if n1:
logging.info('Saving Information to POD')
if original_store['df'] != []:
df = pd.DataFrame(original_store['df'])
engine_name = df.iloc[0, 1]
df['SavGol'] = signal.savgol_filter(df['deviation'], 576, 1)
if new_start_date is None:
new_start_date = df.iloc[0, 2]
logging.info(f'New Start Date: {new_start_date}')
end_date = df.iloc[-1, 2]
logging.info(f'End Date: {end_date}')
# closest = df['date'].searchsorted(f'{new_start_date}T00:00:00')
# initial_savgol = df['SavGol'].iloc[closest]
offset_start = 0
if offset:
offset_start = offset
logging.info(f'Offset: {offset_start}')
store = {
"report": original_store['report'],
"engine": engine_name,
"new_start_date": new_start_date,
"end_date": end_date,
"offset_value": offset_start or None,
"lower_bound": lower_bound or None,
"upper_bound": upper_bound or None,
"events": events,
}
return store
But now it’s telling me:
A nonexistent object was used in an `Input` of a Dash callback. The id of this object is `new-start-date` and the property is `value`. The string ids in the current layout are: [store, store-results, offset-store, _pages_location, _pages_content, _pages_store, _pages_dummy]
The ‘new-start-date’ is on my graph.py. Ironically another callback is using it just fine.
I’m confused because this callback isn’t in app.py and never was but only decided to throw this error when I included the third store. Any ideas as to why this is happening? Clearly I have a gap in my knowledge about how these all connect otherwise I feel like this shouldn’t be that difficult lol.