Hi,
I am trying to update a Graph using Patch and set_prop. I can update a graph using
- Patch and Output
- Figure and Output
- Figure and set_prop
but not using Patch and set_prop. Below is an example trying to extend an existing trace, but I am also interested in the general case (also updating layout, adding traces, …).
from dash import Dash, html, dcc, Input, Output, Patch, callback, set_props
import plotly.graph_objects as go
import datetime
import random
app = Dash()
figPatchOutput = go.Figure(data=go.Scatter(x=[], y=[]), layout={"title": "PatchOutput"})
figFigureOutput = go.Figure(
data=go.Scatter(x=[], y=[]), layout={"title": "FigureOutput"}
)
figFigureSetProp = go.Figure(
data=go.Scatter(x=[], y=[]), layout={"title": "FigureSetProp"}
)
figPatchSetProp = go.Figure(
data=go.Scatter(x=[], y=[]), layout={"title": "PatchSetProp"}
)
app.layout = html.Div(
[
dcc.Graph(figure=figPatchOutput, id="append-patch-output"),
dcc.Graph(figure=figFigureOutput, id="append-figure-output"),
dcc.Graph(figure=figFigureSetProp, id="append-figure-setProp"),
dcc.Graph(figure=figPatchSetProp, id="append-patch-setProp"),
html.Button("Append", id="append-new-val"),
],
style={
"display": "grid",
"gridTemplateColumns": "repeat(4, 1fr)",
"height": "400px",
},
)
@callback(
Output("append-patch-output", "figure"),
Output("append-figure-output", "figure"),
Input("append-new-val", "n_clicks"),
)
def add_data_to_fig(n_clicks):
currentTime = datetime.datetime.now()
random_value = random.randrange(1, 30, 1)
patchedOutput = Patch()
patchedOutput["data"][0]["x"].append(currentTime)
patchedOutput["data"][0]["y"].append(random_value)
patchedSetProp = Patch()
patchedSetProp["data"][0]["x"].append(currentTime)
patchedSetProp["data"][0]["y"].append(random_value)
figFigureOutput["data"][0]["x"] = [*figFigureOutput["data"][0]["x"], currentTime]
figFigureOutput["data"][0]["y"] = [*figFigureOutput["data"][0]["y"], random_value]
figFigureSetProp["data"][0]["x"] = [*figFigureSetProp["data"][0]["x"], currentTime]
figFigureSetProp["data"][0]["y"] = [*figFigureSetProp["data"][0]["y"], random_value]
set_props("append-figure-setProp", {"figure": figFigureSetProp})
set_props("append-patch-setProp", {"figure": patchedSetProp})
return patchedOutput, figFigureOutput
if __name__ == "__main__":
app.run(debug=True)
The error I am getting in Plotly version 6.1.1, Dash version v3.1.0, Windows operating system is
Failed component prop type: Invalid component prop `figure` key `__dash_patch_update` supplied to Graph.
Bad object: {
"__dash_patch_update": "__dash_patch_update",
"operations": [
{
"operation": "Append",
"location": [
"data",
0,
"x"
],
"params": {
"value": "2025-08-06T07:17:26.594381"
}
},
{
"operation": "Append",
"location": [
"data",
0,
"y"
],
"params": {
"value": 6
}
}
]
}
Valid keys: [
"data",
"layout",
"frames"
]
Why is figure not a valid property of a dcc.Graph?