在用dash_bootstrap_components做下来框的时候网页报错“label in Dropdown with ID "dbd" is required but it was not provided”,是什么原因。请各位大拿帮忙解决下。
import tushare as ts
import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
app= dash.Dash("___name___-")
import tushare as ts
TOKEN = "3b05099d7699fefca2d8f6f9b0b3ae3aee3db8b5722d765b4011a3f3"
pro = ts.pro_api(token=TOKEN)
result = pro.stock_basic()
industry_list = list(set(result["industry"]))
print(industry_list)
app.layout =html.Div([
html.H6("行业选择"), #H6含义是标题标签,H1只能用一次,H2-H6可以重复使用
html.Hr(),
dcc.Dropdown(
id="dbd",
options=[{"label":i,"value":i} for i in industry_list],
value="食品")
])
app.run_server(debug=True)
先定义一下options并添加label,value键值对,这样试试:
pro = ts.pro_api(token=TOKEN)
result = pro.stock_basic()
industry_list = result["industry"].unique()
opts = [{'label': i, 'value': i} for i in industry_list if i!=None]#要将空值剔除。
opts.insert(0,{'label': 'dbd', 'value': 'dbd'})
app.layout = html.Div([
html.H6("行业选择"), # H6含义是标题标签,H1只能用一次,H2-H6可以重复使用
html.Hr(),
dcc.Dropdown(
id="dbd",
options=opts,
value='食品')
])
app.run_server(debug=True)