Partial Property Updates - Patch Class

Hi,

Are there any options to create a graph figure within a callback function and update the Patch Assign object in the same callback?
I have read the “Partial Property Updates” section and the examples. I found the figure is created at the beginning, and subsequent patch updates are done within the callbacks.

Thank you

Hi @Anfas are you trying to patch the figure you are creating in the callback or a different figure of your layout?

If the former applies, there is no need for the Patch object since you can alter the figure directly. The partial updates were introduced in order to decrease the data traffic between server and client.

2 Likes

hi @Anfas
Nice observation. Some of the examples we provide around Partial Property Updates create the graph figures at the beginning, but that was only for example purposes. It’s not very common for figures to be created globally or within the layout. Usually you will use one callback to create the figure, and then another callback to update the figure, especially if you’re using Patch to update certain parts of the figure.

1 Like

Hi @adamschroeder @AIMPED,
Thank you for your input.

I have created a figure in a callback using plotly express, and the source data is fetched from the dcc.Store component.

It is a facet histogram figure, where x, color and facet_col parameters are derived from dcc.Dropdown components from the layout.

I managed to patch the x with the following:
patched_fig = Patch()
patched_fig[‘data’][0][‘x’] = dff[x].values

But, I could not find the correct structure to patch color and facet_col parameters.

Could you please help?

Thanks again.

The thing is, that plotly.express does some things under the hood for you such as grouping the data or adding traces of different colors for example.

In the end it all translates into the go.Figure() structure. So you need to inspect the figure object. I usually convert it into a dictionary with fig.to_dict() and derive the necessary Patch() structure.

If you shared your code and data, we could help you in more detail.

2 Likes

I’m looking for update color and facet_col parameters.

I read @adamschroeder detailed thread on this Adam post

Specifically, on the below extract:

9. update Dictionaries Patch()[“data”][0][“marker”].update({“color”: “red”})

In my case, the color is derived from a categorical column in the df.

Also, for facet_col parameter.

Thanks

hi @Anfas
Are you able to share your code and data like @AIMPED requested?

1 Like

Yeah exactly, here are a couple of docs that go into some of the detail:

1 Like