What I’ve tried and what’s not working:
Error like below.
anvil.server.SerializationError: Cannot serialize return value from function. Cannot serialize <class ‘plotly.graph_objs._figure.Figure’> object at msg[‘response’]
Thanks for sharing the link. I have figured out how to deal with it properly. The logic is
save your figure to json from your local server by fig.to_json()
pass the json to client by a function call
give the value of data and layout separately by self.plot_1.data = json.loads(resp)[‘data’] and self.plot_1.layout = json.loads(resp)[‘layout’] and it will work.
I wish one day Anvil will make plotly.io.from_json and go.Figure available on the client side.
def show_fig1(self, **event_args):
“”“This method is called when the Plot is shown on the screen”""
figure, data, layout = anvil.server.call(“show_fig1”)
self.fig1.figure = figure
self.fig1.data = data
self.fig1.layout = layout
pass