Plotting with plotly go using uplink prepared code - failing to plot

Hello there again :wave:

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

Uplinked file:

import pandas as pd
import anvil.server
import plotly.graph_objects as go


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


server side code:

import anvil.server
import pandas as pd
import plotly.graph_objects as go

def call_df():
  x, y ='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.

    # Any code you write here will run when the form opens.
    fig ='return_df')
    self.plot_1.figure = fig

resulting to a figure without any plot.

Thanks for your help.


Just a quick look and you’re calling return_df in the client when you mean to call your call_df function.

1 Like

oh dear, sorry and thanks :slight_smile: