【问题标题】:How can I create two separate buttons with two separate inputs in Plotly Dash?如何在 Plotly Dash 中创建两个具有两个单独输入的单独按钮?
【发布时间】:2021-09-27 08:58:48
【问题描述】:

我需要的很简单。

一个打印“A”的按钮。

另一个打印“B”的单独按钮。

这两个按钮没有任何关系。

如何通过使用两个单独的回调在 plotly dash 中做到这一点?

【问题讨论】:

    标签: python plotly plotly-dash plotly-python


    【解决方案1】:
    • 构建这个最小的例子。我发现 callback 需要 Output
    • 直接使用 Div 来满足此要求
    from jupyter_dash import JupyterDash
    import dash_core_components as dcc
    import dash_html_components as html
    from dash.dependencies import Input, Output, State
    
    # Build App
    app = JupyterDash(__name__)
    app.layout = html.Div(
        [
            html.Button("Button A", id="button-a", n_clicks=0),
            html.Button("Button B", id="button-b", n_clicks=0),
            html.Div(id="out-a"),
            html.Div(id="out-b"),
        ],
    )
    
    @app.callback(
        Output("out-a", "children"),
        Input("button-a", "n_clicks"),
    )
    def buttonA(nClicks):
        print("button A")
        return None
    
    @app.callback(
        Output("out-b", "children"),
        Input("button-b", "n_clicks"),
    )
    def buttonB(nClicks):
        print("button B")
        return None
    
    
    
    # Run app and display result inline in the notebook
    app.run_server(mode="inline")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-30
      • 2019-08-01
      • 1970-01-01
      • 2020-04-08
      • 2021-04-19
      • 1970-01-01
      相关资源
      最近更新 更多