set_props does not work with Patch()
Describe the bug
set_props does not work with Patch. I guess, it replaces the Figure object with a Patch object instead of merging them.
As a result, in order to update a figure partially, one has to use old-style Output in server-side callbacks.
I haven't seen anything in the docs that would suggest that this is expected behaviour.
Expected behavior
set_props works with Patch or Figure equally well when updating Graph component's figure property.
Reproduce
Code to reproduce
import numpy as np
import plotly
from plotly import express as px, graph_objects as go, figure_factory as ff
from dash import Dash
from dash import html, dcc, callback, Input, Output, Patch, set_props
def make_figure():
x = np.arange(6)
y = np.random.randint(6, size=(10))
return go.Figure(go.Scatter(x=x, y=y))
fig1 = make_figure()
button1 = html.Button("Output()", id="button1", n_clicks=0)
button2 = html.Button("set_props", id="button2", n_clicks=0)
children = [button1, button2, dcc.Graph(id="fig1", figure=fig1)]
@callback(
Output("fig1", "figure", allow_duplicate=True),
Input("button1", "n_clicks"),
prevent_initial_call=True,
)
def regenerate_1(n_clicks):
fig1 = make_figure()
patch = Patch()
patch["data"] = fig1["data"]
fig1 = patch # comment/uncomment this
return fig1
@callback(
Input("button2", "n_clicks"),
prevent_initial_call=True,
)
def regenerate_2(n_clicks):
fig1 = make_figure()
patch = Patch()
patch["data"] = fig1["data"]
fig1 = patch # comment/uncomment this
set_props("fig1", {"figure": fig1})
app = Dash()
app.layout = html.Div(children)
app.run(jupyter_mode="external", port=8051)
`pip list | grep dash` below
dash 2.18.1
dash-bootstrap-components 1.6.0
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-mantine-components 0.12.1
dash-table 5.0.0
@gvwilson User https://github.com/yuvashrikarunakaran who posted above is engaging in disruptive behaviour. I am not sure if this is a bot, a person in a mental crisis, or both, but you can see from their profile that they are making trivial commits to many repositories, which have been rejected by every other organisation except for Plotly. You can also read the senseless comments they made in this repository.
May I suggest that you ban this user and enable abuse reports for this repository to streamline resolution of similar issues in the future.
@avm19 thank you for the report. @yuvashrikarunakaran can you please contact us at within the next 24 hours at [email protected]
We've noticed issues with your contributions and comments that need to be discussed.