I am having a difficult time figuring out how to best add traces to a subplot in a callback in Dash like is done here https://community.plotly.com/t/extend-or-append-data-instead-of-update/8898/2 for a normal plot.
For Example (pseudo-code):
@app.callback(Output('subplot-plot', 'figure'), [Input('button-component', 'n_clicks')], [State('subplot-plot', 'figure')])
def add_sub_plot_trace(n_clicks, figure):
figure.add_trace('some_trace_data', row=1, col=2) # does not work figure is a dict
figure = go.Figure(**figure).add_trace('some_trace_data', row=1, col=2) # does not work missing '_grid_ref'
figure = go.Figure(data=figure).add_trace('some_trace_data', row=1, col=2) # does not work missing '_grid_ref'
figure = make_subplots(rows=2, cols=3, figure=go.Figure(**figure).add_trace('some_trace_data', row=1, col=2) # kind of works but gives some strange result, not ideal because of need to reinstate subplot
# polar subplots inparticular are not happy with the above even with the specs kwarg included in make subplots
return figure
Hopefully, I am just missing something!
Thank you!!