What I’m trying to do:
Following Build a Dashboard with Python tutorial found here
I cannot get data to plot when calling build_revenue_graph which is setup to fetch data from Anvil’s Data Table services. Specifically I get the following runtime error:
AttributeError: Cannot set attribute 'main_plot_top_left' on 'Form1' form. There is already a component with this name.
at Form1, line 21
called from Form1, line 14
What I’ve tried and what’s not working:
In the design tab I named The plot object where the data will be placed as main_plot_top_left
Changing this to any other name will clear the error message at run-time but as expected nothing will actually plot to that plot object.
I then added the function build_test_graph() and commented out build_revenue_graph().
This ranas intended, and the object name was the same.
Now I realized what the problem is, i forgot adding .data at the end of variable name “self.main_plot_top_left”
Since I have all of this typed up already I figured i’d post it anyways in case someone else searches for a similar error message.
Code Sample:
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.build_revenue_graph()
self.build_test_graph()
# Any code you write here will run when the form opens.
def build_revenue_graph(self):
db_data = anvil.server.call('get_revenue')
self.main_plot_top_left = go.Bar(x =[x['Expected ATR'] for x in db_data],
y =[x['Expected Date']for x in db_data],
marker=dict(color='#2196f3'))
def build_test_graph(self):
self.main_plot_bottom_left.data = go.Bar(y=[100,400,200,300,500])