json无法正确填充Dash中的下拉列表

时间:2018-10-24 19:43:53

标签: python-3.x plotly-dash

下面的代码运行(缓慢),但这是因为它正在串联json列表。如果我添加

{'label': 'Apple Inc', 'value: 'AAPL'} {'label': 'General Electric, Inc', value: 'GE'} {etc, etc....}

它可以快速高效地工作,而不是jname和jsymbol的变量。我正在尝试使用iexfinance改编Hello_Dash初学者示例,因为google和yahoo api似乎不起作用。

get_available_symbols是一个相当长的json。

import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
from iexfinance import get_historical_data as ghd
from pandas_datareader import data as web
from datetime import datetime as dt
import pandas as pd
from iexfinance import Stock as Cpx
from iexfinance import get_available_symbols as gas


app = dash.Dash('All Stocks')
dfgas = gas()[:]
jname = pd.DataFrame(ticker, index = name)
jname = [[piece['name'] for piece in dfgas]]
jsymbol = [[piece['symbol'] for piece in dfgas]]
app.layout = html.Div([
dcc.Dropdown(
    id='my-dropdown',
    options=[
        {'label': jname, 'value': jsymbol}
    ],
    value = 'AAPL'
),
dcc.Graph(id='my-graph')
], style={'width': '500'})

from dateutil.relativedelta import relativedelta as rd

start = dt.now() - rd(years = 5)

@app.callback(Output('my-graph', 'figure'), [Input('my-dropdown', 'value')])
def update_graph(selected_dropdown_value):
df = ghd(selected_dropdown_value, start=start, end=dt.now(), output_format='pandas')
#start=(start, end=dt.now())
return {
    'data': [{
        'x': df.index,
        'y': df.close
    }],
    'layout': {'margin': {'l': 40, 'r': 0, 't': 20, 'b': 30}}
}

app.css.append_css({'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'})

if __name__ == '__main__':
app.run_server()

任何帮助将不胜感激

0 个答案:

没有答案