I’m using the new Patch() feature to extend my graphs on update instead of reloading each expensive graph. It’s not clear to me from the documentation how I can extend graphs with multiple traces. In the example below, I have a box plot that I can extend, however, I would like to extend the scatter plot as well, but I’m not certain how to specify which plot I’m extending. Thanks.
“”"
from dash import Dash, html, dcc, Input, Output, Patch
import plotly.graph_objects as go
app = Dash(name)
fig = go.Figure(
[
go.Box(x=[‘08:15’,‘08:15’,‘08:15’], y=[120,80,60]),
go.Scatter(x=[‘08:15’], y=[100]),
],
go.Layout(
dict(
annotations=[
dict(
x=‘08:15’,
y=130,
text=“95”,
showarrow=False,
),
]
),
showlegend=False,
),
)
app.layout = html.Div([
html.Button(“Show/Clear Annotations”, id=“clear-button”),
dcc.Graph(id=“clear-example”, figure=fig),
])
@app.callback(
Output(“clear-example”, “figure”),
Input(“clear-button”, “n_clicks”),
prevent_initial_call=True,
)
def add_data_to_fig(n_clicks):
patched_figure: object = Patch()
blood_pressure =[[120,80,60],[121,80,60],[122,80,60]]
triple_time = [[‘08:15’,‘08:15’,‘08:15’],[‘08:20’,‘08:20’,‘08:20’],[‘08:30’,‘08:30’,‘08:30’]]
hr = data_list[0]
for x in triple_time:
patched_figure[“data”][0][“x”].extend(x)
for y in blood_pressure:
patched_figure[“data”][0][“y”].extend(y)
return patched_figure
if name == “main”:
app.run_server(debug=True)
“”"