I have been working with Anvil for about 1 week and I am extremely confused by the documentation. I am making an api call via the server module and am able to print the return but for the life of me I cannot understand the process of getting a plot to show. Maybe something simple but I find the docs to be really vague at times and they seem to skip allot of details…
This is my form code:
from ._anvil_designer import Form2Template
from anvil import *
import plotly.graph_objects as go
import anvil.server
import json
class Form2(Form2Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run before the form opens.
stock_data = anvil.server.call('get_stock_history_tradier', 'aapl', 'daily', 'month')
print(stock_data)
self.plot_1.data = go.Scatter(x =[p['history']['day']['date'] for p in stock_data],
y = [p['history']['day']['close'] for p in stock_data],
fill = 'tozeroy')
Clone link:
share a copy of your app
this is my api print;
{'history': {'day': [{'close': 150.87, 'date': '2023-02-09', 'high': 154.33, 'low': 150.42, 'open': 153.775, 'volume': 56007143}, {'close': 151.01, 'date': '2023-02-10', 'high': 151.3401, 'low': 149.22, 'open': 149.46, 'volume': 57450708}, ......
this is my error message
TypeError: string indices must be integers, not str
at Form2, line 22
I have tried many possible combos but I am missing something