Faults encountered in dash callback. Procedure

dxl19861227 注册会员
2023-02-28 20:21

But this is still only one dropdown input, if you add button, The first function's callback has an extra variable(dropdown_value,radioitem_value), and there seems to be no way to determine which value to return.

loshineve 注册会员
2023-02-28 20:21

This answer quotes ChatGPT

When you need to control the same output with Dropdown and Button, you can use dcc.Store to store your variables and update it when the user changes either control. You can then use the Input component and one or more State components to implement your callback functions to update your output based on recent variable changes.

Here is a sample code that shows how to implement the behavior you describe:

import dash
import dash_core_components as dcc
import dash_html_components as html
om dash.dependencies import Input, Output, State

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Store(id='fruit-storage', data=''),
            {'label': 'Apple', 'value': 'apple'},
            {'label': 'Pear', 'value': 'pear'},
            {'label': 'Peach', 'value': 'peach'}
        placeholder='Select a fruit'
    html.Button('Submit', id='submit-button', n_clicks=0),

    Output('fruit-storage', 'data'),
    Input('submit-button', 'n_clicks'),
    State('fruit-dropdown', 'value'),
    State('fruit-storage', 'data')
def update_fruit_data(n_clicks, dropdown_value, stored_data):
    if n_clicks > 0:
        return dropdown_value
    return stored_data

    Output('output', 'children'),
    Input('fruit-dropdown', 'value'),
    Input('submit-button', 'n_clicks'),
    State('fruit-storage', 'data')
def update_output(dropdown_value, n_clicks, stored_data):
    if n_clicks == 0:
        return ''
    if stored_data == '':
        return ''
    return f'{stored_data}, {dropdown_value}'

if __name__ == '__main__':

In this example code, fruit-storage stores the fruit selected before the last click of the button, fruit-Dropdown is a drop-down menu that allows the user to select a fruit, and submit-button is a button that when the user clicks it, Saves the most recent selection to fruit-storage. output is a div element that displays the last two selections.

About the Author

Question Info

Publish Time
2023-02-28 20:21
Update Time
2023-02-28 20:21

Related Question

Arduino HTTP.post()返回-11

linux python 版本默认的问题

Excel上传在springboot qraphql

Vue PWA在导航到路由时抛出错误,在css文件中显示index.html


Int传入Intent,但是Android studio说我传递了一个字符串

socketexception: Jenkins用户帐户中的连接重置


对于运行Kubernetes 1.22的EKS集群,使用fluent-concat-plugin连接分裂日志消息

参数#1 ($content)必须是?string类型