# Partial Property Updates - Patch Class

**URL:** <https://community.plotly.com/t/partial-property-updates-patch-class/74713>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [April 24, 2023, 7:14pm UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713 "2023-04-24T19:14:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anfas](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@Anfas](https://community.plotly.com/u/Anfas)\
**Post date:** [April 24, 2023, 7:14pm UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713/1 "2023-04-24T19:14:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [April 25, 2023, 9:13am UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713/2 "2023-04-25T09:13:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [April 25, 2023, 2:46pm UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713/3 "2023-04-25T14:46:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Anfas](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@Anfas](https://community.plotly.com/u/Anfas)\
**Post date:** [April 25, 2023, 5:18pm UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713/4 "2023-04-25T17:18:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [April 25, 2023, 5:56pm UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713/5 "2023-04-25T17:56:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Anfas](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@Anfas](https://community.plotly.com/u/Anfas)\
**Post date:** [April 25, 2023, 7:38pm UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713/6 "2023-04-25T19:38:08Z")

</div>

I’m looking for update **color** and **facet\_col** parameters.

I read @adamschroeder detailed thread on this [Adam post](https://community.plotly.com/t/dash-2-9-2-released-partial-property-updates-with-patch-duplicate-outputs-dcc-geolocation-scatter-group-attributes-and-more/72114)

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

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [April 25, 2023, 8:34pm UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713/7 "2023-04-25T20:34:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [April 25, 2023, 9:01pm UTC](https://community.plotly.com/t/partial-property-updates-patch-class/74713/8 "2023-04-25T21:01:53Z")

</div>

> [@AIMPED](#):
>
> 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.

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

- [The figure data structure in Python](https://plotly.com/python/figure-structure/)
- [Creating and updating figures in Python](https://plotly.com/python/creating-and-updating-figures/#plotly-express)
