我正在尝试使用 Dash Plot 将输入值传递给另一个。
主页上有一个策略列表:
First_page = html.Div([
html.Div([dcc.Dropdown(id='strategy', options=[{'label': i, 'value': i} for i in [strat1, start2]], multi=True)], value = [strat1]),
html.Div([dcc.Input(id='date_start', type='text', value='1990-01-01')]),
html.Button('Start Calculation', id='button'),
])
我的第 1 页和第 2 页如下:
for i in range(2) :
layout = html.Div([
html.Div([dcc.Dropdown(id='strategy'+str(i), options=[{'label': i, 'value': i} for i in [strat1, start2]]])], value = strat+str(i)),
html.Div([dcc.Input(id='date_start'+str(i), type='text', value='1990-01-01')]),
html.Button('Start Calculation', id='button'+str(i)),
+ other options not listed in main page
])
目标如下:当用户在主页上时,他可以选择他想要查看的策略列表以及开始日期。
然后当他按下按钮时,它应该为每个选择的策略打开页面(在这个例子中我们有 2 个策略,所以我应该有 2 个页面:localhost:port/page-strat1 和 localhost:port/page-strat2),如图所示在每一页上都以所选日期开始。
我成功打开页面 localhost:port/strat1 和/或页面 localhost:port/strat2 取决于所选策略的列表。
list_event = [Event('button', 'click')]
list_state = [State('strategy', 'value')]
@app.callback(Output('hidden-div', 'children'),events=list_event, state=list_state)
def create_callback_share(datestart, list_strategies_used):
for _strat in list_strategies_used:
time.sleep(1)
webbrowser.open('http://localhost:port/page-'+_strat)
但是我没有成功发送所选日期。我尝试以下回调:
for i in range(2) :
@app.callback(Output('date_start'+str(i), 'value'),inputs=[Input('date_start', 'value')])
def set_display_children(selected_element):
return "{}".format(selected_element)
但是页面 localhost:port/strat1 和 localhost:port/strat2 允许以默认值“1990-01-01”打开,即使我在主页中输入另一个值。
是否可以将值从一页发送到另一页?
最佳答案
使用 dcc.Store()
正如这里的答案:
Plotly Dash Share Callback Input in another page with dcc.Store
这是 Dash 文档:
https://dash.plotly.com/dash-core-components/store
关于python - 在破折号中将值从一页传递到另一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50977636/