python - 如何在 Plotly Dash 中创建两个带有两个单独输入的单独按钮?
问题描述
我需要的很简单。
一个打印“A”的按钮。
另一个打印“B”的单独按钮。
这两个按钮绝不是相关的。
如何通过使用两个单独的回调在情节破折号中做到这一点?
解决方案
- 构建了这个最小的例子。我发现回调需要输出
- 已使用直接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")
推荐阅读
- android - OkHttp SSLProtocolException:SSL 握手在 android 4 上中止
- css - 使用动画的带有箭头的 CSS 滑块
- python - django修改数据库对象
- javascript - React JS:FirebaseUI 身份验证持久性适用于 Firefox Mobile 而不是 Chrome Mobile
- laravel-5.4 - 如何在 laravel 5.4 中只在自己的城市看到专家
- json - 如何将 servlet 请求转换为 JSON 请求
- android - 仅从一个片段中不显示片段
- ios - iOS 目标 C 完成块不会在 Azure 移动应用程序框架方法需要的地方返回数据。构建捆绑应用程序
- apache - 在 Hybris 中设置 mod_jk 重定向
- wordpress - 在 wordpress 中添加新页面时无法选择作品集类别