Hi,
I’ve got a callback function to update a chart. It takes in a dataframe from a hidden div.
The problem is that on page load the dataframe is empty and the code breaks because of this. The dataframe will only contain data once the user makes a selection from a dropdown menu.
I only want the chart update callback function to run after the user makes a selection from a dropdown menu.
I have put in an if statement to test whether the dataframe is empty. That stops the syntax errors but now it looks like the callback function doesn’t fire when a user makes a selection. Can someone please advise what I am doing wrong?
@app.callback(
dash.dependencies.Output(‘payoff_graph’, ‘figure’),
[dash.dependencies.Input(‘filtered_df’, ‘children’)]
)
def update_chart(json_data):
df_filter = pd.read_json(json_data, orient=‘split’)
if not df_filter.empty:
issuer = df_filter[df_filter['Security Type'] == 'OS']['Security'].values[0]
min_price = 0
max_price = max(df_filter['Market Price'].max(), df_filter['Excercise Price'].max()) * 1.2
prices = np.arange(min_price, max_price, 0.01)
df_payoff = pd.DataFrame(index=prices)