plotly - 保存下拉列表的选定值并默认在另一个下拉列表/重复下拉列表中分配它
问题描述
我想知道是否可以保存下拉列表的选定值并默认将其放在具有相同值但位于另一个选项卡中的下拉列表中:
uriCounts 选项卡
dcc.Tab(label='uriCounts', value = 'es_uricounts', children = [
html.Div([
html.Br(),
html.H3("Choose uriCounts file version: "),
dcc.Dropdown(id='uriCounts_dropdown',options=[
{'label': 'Oct 1st 2016', 'value': 'Oct 1st 2016'},
{'label': 'Oct 1st 2020', 'value': 'Oct 1st 2020'},
{'label': 'May 25th 2021', 'value': 'May 25th 2021'},
{'label': 'Jun 25th 2021', 'value': 'Jun 25th 2021'}],
placeholder="Version"),
html.Br(),
html.Div(id='uriCounts_container')
],style = {'margin-left': '3.2552083333333335vw', 'margin-right': '3.2552083333333335vw'})
], style = tab_style, selected_style = tab_selected_style)
对计数选项卡
dcc.Tab(label='pairCounts', children = [
html.Div([
html.Br(),
html.H3("Choose pairCounts file version: "),
dcc.Dropdown(id='pairCounts_dropdown',options=[
{'label': 'Oct 1st 2016', 'value': 'Oct 1st 2016'},
{'label': 'Oct 1st 2020', 'value': 'Oct 1st 2020'},
{'label': 'May 25th 2021', 'value': 'May 25th 2021'},
{'label': 'Jun 25th 2021', 'value': 'Jun 25th 2021'}],
value=**uriCounts_value**),
html.Br(),
html.Div(id='pairCounts_container')
], style = {'margin-left': '3.2552083333333335vw', 'margin-right': '3.2552083333333335vw'})
], style = tab_style, selected_style = tab_selected_style)
当您在选项卡的下拉列表中选择一个值时uriCounts
,我希望选项卡的下拉列表中pairCounts
分配该值。
如果它可以以相反的顺序完成也很好:首先在选项卡的下拉列表中选择一个值,pairCounts
然后在选项卡的下拉列表中选择该uriCounts
值
希望你能帮我解决这个问题。提前致谢。
解决方案
@AnnMarieW 在Dash 社区论坛中给了我这个解决方案
在回调中同步下拉列表是一种可能的解决方案:
@app.callback(
Output('dropdown1', 'value'),
Output('dropdown2', 'value'),
Input('dropdown1', 'value'),
Input('dropdown2', 'value'),
)
def sync_dropdowns(val1, val2):
ctx = dash.callback_context
input_id = ctx.triggered[0]['prop_id'].split('.')[0]
if input_id == 'dropdown1':
return dash.no_update, val1
else:
return val2, dash.no_update
推荐阅读
- here-api - HERE Maps Api 反向地理编码和街道/道路方位
- generics - 返回通用结构的函数的签名是什么?
- xml - 如何在公共 API 合约中更好地组织 XML 数据中任意类型的存储?
- uitextfield - SwiftUI 如何获取对 List 内编辑 Textfield 的引用?
- wordpress - 从 woocommerce 中删除面板
- jakarta-mail - 每个文件夹都是 JavaMail IMAP 的 UIDFolder
- flutter - 如何缩放文本小部件,其行为类似于图像的缩放
- html - mod_rewrite 规则是否适用于网站请求的资源
- wordpress - 将简单产品添加到 Woocommerce 后,页面上没有购买按钮
- php - 可以使用 preg_split 将字符串拆分为数组,同时删除任何空格吗?