非常感谢有关如何为我的 Dash Web 应用程序进行正确回调的一些帮助。我在下面有以下代码。它应该返回一个图表,其中包含有关股票财务状况的各种线条。它从 API 获取数据。但我不确定如何为应用回调定义我的函数。我尝试过遵循在线教程,但取得了任何成功。如果它太混乱或效率低下,我深表歉意,我是新手。
'''
#!/usr/bin/env python
import pandas as pd
import requests
import json
import plotly
import chart_studio.plotly as py
import plotly.graph_objs as go
import plotly.express as px
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Output, Input
ticker = input("Insert company ticker: ")
qoy = input("QUARTERLY or YEARLY: ")
if qoy == "Yearly" or qoy == "yearly" or qoy == "YEARLY":
IS = requests.get("https://financialmodelingprep.com/api/v3/financials/income-statement/" + ticker)
elif qoy == "Quarterly" or qoy == "quarterly" or qoy == "QUARTERLY":
IS = requests.get(
"https://financialmodelingprep.com/api/v3/financials/income-statement/" + ticker + "?period=quarter")
IS = IS.json()
IS = IS['financials']
IS = pd.DataFrame.from_dict(IS)
IS = IS.set_index("date")
if qoy == "Yearly" or qoy == "yearly" or qoy == "YEARLY":
BS = requests.get("https://financialmodelingprep.com/api/v3/financials/balance-sheet-statement/" + ticker)
elif qoy == "Quarterly" or qoy == "quarterly" or qoy == "QUARTERLY":
BS = requests.get(
"https://financialmodelingprep.com/api/v3/financials/balance-sheet-statement/" + ticker + "?period=quarter")
BS = BS.json()
BS = BS['financials']
BS = pd.DataFrame.from_dict(BS)
BS = BS.set_index("date")
if qoy == "Yearly" or qoy == "yearly" or qoy == "YEARLY":
CF = requests.get("https://financialmodelingprep.com/api/v3/financials/cash-flow-statement/" + ticker)
elif qoy == "Quarterly" or qoy == "quarterly" or qoy == "QUARTERLY":
CF = requests.get(
"https://financialmodelingprep.com/api/v3/financials/cash-flow-statement/" + ticker + "?period=quarter")
CF = CF.json()
CF = CF['financials']
CF = pd.DataFrame.from_dict(CF)
CF = CF.set_index("date")
df_FS = pd.concat([IS, BS, CF], axis=1, sort=True)
Date = df_FS.index
df_FS.fillna(0, inplace=True)
print(df_FS)
慕码人2483693
相关分类