在Dash中动态填写下拉列表

时间:2020-06-02 18:31:50

标签: python python-3.x hyphen

我有一个问题,在数据帧中运行sql语句后。我确定我错过了一些简单的事情,但它阻碍了我的工作,并且使我的仪​​表板项目无法顺利进行。

在下面的代码中,当我运行它时,在下拉列表中我只能看到UNUM,我无法弄清楚我在做错什么以从中获取价值。我可以毫无问题地打印eqid,但是我无法正确地对其进行迭代。感谢您的协助

import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import dash_table

import pandas as pd
import sqlite3

import plotly.graph_objs as go

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

conn = sqlite3.connect(
    r"mysqlfile")
c = conn.cursor()

eqids = pd.read_sql("SELECT distinct UNUM FROM AllTestData", conn)
#names = list(eqids.keys())
print(eqids)
'''df = pd.read_sql("select * from AllTestData", conn)
df = df[['UNUM', 'DT_TAKEN', 'Iron', 'Chromium', 'Lead', 'Copper', 'Tin', 'Aluminum', 'Nickel', 'Silver', 'Silicon', 'boron', 'Sodium', 'Magnesium', 'Calcium', 'Barium', 'Phosphorous', 'Zinc',
         'Molybdenum', 'Tin1', 'Vandium', 'W', 'Potassium', 'Antimony', 'Lithium', 'Maganese', 'Cadmium', 'VISC40', 'TAN', 'KFISH', 'WATER', 'PC0', 'PC1', 'pc2', 'pc3', 'pc4', 'pc5', 'PCISO0', 'PCISO1', 'PCISO2']]
df.head(1)
'''

app.layout = html.Div([
    html.Label('Select Equipment ID'),
    dcc.Dropdown(
        id='equipment-list',
        options=[{'label': i, 'value': i} for i in eqids],
    ),
    dcc.Graph(id='test-graph')
    # html.Div(id='test-graph')
])


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

1 个答案:

答案 0 :(得分:0)

哦,我的选项代码中需要这个eqids.UNUM。