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.
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.
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.
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.