如何在Plotly Dash中创建具有两个独立输入的两个独立按钮



我需要的很简单。

一个按钮打印";A";。

另一个"分离"按钮;B";。

这两个按钮根本没有关联。

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

  • 构建了这个最小的示例。我发现回调需要输出
  • 已使用直接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")

最新更新