当在Python Dash中选择一个选项时,动态更改下拉选项
我有4个值的下拉值,['all','a','b','c'],我可以选择其中的许多。
dcc.Dropdown(
id='test',
options=[{'label': i, 'value': i} for i in ['All', 'a', 'b', 'c']],
value='All',
clearable=False,
multi=True,
),
现在,是否可以动态更改选项,以便在使用“全部”时,将自动删除所有其他选定的条目? 类似的内容:
@app.callback(
Output('test', 'options'),
Input('test', 'value'),
)
def update_ticker_options(value):
if 'All' in value:
ticker = 'All'
return ticker
该应用程序不是从此代码开始的,因此它不起作用。
I have a dropdown of 4 values, ['All', 'a', 'b', 'c'], where I can select many of them.
dcc.Dropdown(
id='test',
options=[{'label': i, 'value': i} for i in ['All', 'a', 'b', 'c']],
value='All',
clearable=False,
multi=True,
),
Now, is it possible to dynamically change the options, such that when 'All' is used, all other selected entries are removed automatically?
Something like this:
@app.callback(
Output('test', 'options'),
Input('test', 'value'),
)
def update_ticker_options(value):
if 'All' in value:
ticker = 'All'
return ticker
The app is not starting with this code, so it is not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢易卜拉欣,
我将您的答案进行了进一步修改,因为我希望它显示“全部”,而不是所有其他价值观。该代码可以完成工作:
Thank you Ibrahim,
I modified your answer even a bit further, since I want it to show 'All' and not all other values. This code does the work:
我根据所需的功能编辑了您的示例代码。基本上,您需要的是将
输出
参数更改为value
,如下所示。应该发生的事情是,当选择所有
被选中时,所有其他选项都应添加我在列表中作为示例中的所有选项。该列表应返回到下拉列表中的value
参数。I edited your example code based on the functionality you need. Basically what you need is to change the
Output
parameter to bevalue
as shown below. What should happen is whenall
is selected all the other options should be added which I included in a list as an example. This list should be returned to thevalue
parameter in the dropdown.