【发布时间】:2020-12-21 19:19:44
【问题描述】:
我有以下函数将下拉选择与文件路径相关联:
def origin_func():
return html.Div(
children=[
dcc.Markdown('Select country'),
dcc.Dropdown(
id='origin_div',
options=[{'label': 'Malta', 'value': './data/malta.csv'}, {'label': 'Japan', 'value': './data/japan.csv'}],
value='./data/malta.csv'
)
]
)
通过回调,我可以将这个选择变成 Pandas DataFrame:
@app.callback(
Output('country_table', 'children'),
Input('origin_div', 'value')
)
def countrytable(origin_div):
df = pd.read_csv(origin-div)
return df
问题是,我如何将存储在 Dash 变量 ('country_table') 中的 Pandas DataFrame 传递到布局函数中,例如:
def destination_func():
children=[
dcc.Markdown('Select country of destination'),
dcc.Dropdown(
id='destination_div',
options=[{'label': i, 'value': i} for i in df['Destination'].drop_duplicates()],
value=df['Destination'].drop_duplicates()[0]
)
]
)
【问题讨论】:
标签: python html plotly-dash