Hello there again
I am trying anvil and trying to plot something with plolty.
I have made an uplink code that takes a csv file transform it into a pandas data frame and return.
When I am sending the pandas df with to_dict method I get serialization error when calling the function.
Is there any solution to send dataframe without serialization error?
But my real question follow:
I tried to send lists for x and y axis. It s working but nothing is plotted. Whereas the same code locally in a test.py file works.
import pandas as pd import anvil.server import plotly.graph_objects as go anvil.server.connect("mykey") @anvil.server.callable def return_df(): df = pd.read_csv('data.csv') df = df.groupby('city').mean().reset_index() x = df['city'].to_list() y = df['temperature'].to_list() #x=[1,2,3] I tried those lists too #y=[100, 200, 300] I tried those lists too return x, y anvil.server.wait_forever()
server side code:
import anvil.server import pandas as pd import plotly.graph_objects as go @anvil.server.callable() def call_df(): x, y = anvil.server.call('return_df') fig = go.Figure(go.Bar(x=x, y=y)) return fig
Client side code:
from ._anvil_designer import Form1Template from anvil import * import plotly.graph_objects as go import anvil.server class Form1(Form1Template): def __init__(self, **properties): # Set Form properties and Data Bindings. self.init_components(**properties) # Any code you write here will run when the form opens. fig = anvil.server.call('return_df') self.plot_1.figure = fig
resulting to a figure without any plot.
Thanks for your help.