python - Dynamically Fill Out Dropdown in Dash
问题描述
I have an issue that after I run my sql statement in a data frame. I'm sure I'm missing something easy but its holding me up big time and I'm having issues getting my dashboard project even off the ground.
In the below code All I can get in the dropdown is UNUM when I run it and I can't figure out what I'm doing wrong to get my values out of it. I can print eqids with no issue but I can't iterate over it correctly. Thanks for the assistance
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)
解决方案
哦,我的选项代码中需要这个 eqids.UNUM。
推荐阅读
- css - 如何检查是否存在 HTML 元素并仅使用 CSS 或 Sass 向其中添加文本?
- c++ - 加法时如何使负数不计入(C++)
- javascript - 发出 POST 请求的 S3 静态网站
- python - 正则表达式字符串匹配 - 潜在的反斜杠问题
- assembly - 如何在 riscV(32 位)中反转 32 位寄存器,是否有命令?
- c# - 接口授予对对象的访问权限?
- c++ - 为什么 (*callback)() 在 c++ 中有效,而不是 *callback() 或 *callback
- python - 标签更新太频繁
- javascript - 删除行空格
- simulation - 一个代理的并行活动