cls*_*udt 4 css python user-interface dashboard plotly-dash
在我的基于Dash的应用程序中,一个按钮会触发一个长时间运行的计算。在结果尚未出现时显示加载动画,并使按钮处于非活动状态,以便在计算完成之前不会再次单击它,这不是很好吗?
我正在使用Bulma进行 UI 设计,并希望button is-loading为此目的使用CSS 类。
我的第一个想法是有两个回调:一个由单击按钮触发以将按钮设置为is-loading,另一个由输出更改触发以将其设置回正常。
@app.callback(
Output('enter-button', 'className'),
[
Input('graph', 'figure')
],
)
def set_trend_enter_button_loading(figure_changed):
return "button is-large is-primary is-outlined"
@app.callback(
Output('enter-button', 'className'),
[
Input('enter-button', 'n_clicks')
],
)
def set_trend_enter_button_loading(n_clicks):
return "button is-large is-primary is-outlined is-loading"
Run Code Online (Sandbox Code Playgroud)
显然它不能那样工作:
dash.exceptions.CantHaveMultipleOutputs:
You have already assigned a callback to the output
with ID "enter-button" and property "className". An output can only have
a single callback function. Try combining your inputs and
callback functions together into one function.
Run Code Online (Sandbox Code Playgroud)
任何想法如何使这项工作?
上周我遇到了同样的问题,甚至尝试使用 Javascript 实现禁用按钮的行为,但最终放弃了。我在plotly 论坛上看到过讨论,显然需要这种类型的功能,但我认为在当前版本中不容易实现。
不过,Dash 开发人员提到的一种临时解决方案是添加全局加载屏幕,这是可能的一件事。简而言之,您需要将以下 CSS 添加到样式表中:
@keyframes fadein {
0% {
opacity: 0;
}
100% {
opacity: 0.5;
}
}
._dash-loading-callback {
font-family: sans-serif;
padding-top: 50px;
color: rgb(90, 90, 90);
/* The banner */
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
text-align: center;
cursor: progress;
opacity: 0;
background-color: rgb(250, 250, 250);
/* Delay animation by 1s to prevent flashing
and smoothly transition the animation over 0.5s
*/
-moz-animation: fadein 0.5s ease-in 1s forwards; /* Firefox */
-webkit-animation: fadein 0.5s ease-in 1s forwards; /* Safari and Chrome */
-o-animation: fadein 0.5s ease-in 1s forwards; /* Opera */
animation: fadein 0.5s ease-in 1s forwards;
}
Run Code Online (Sandbox Code Playgroud)
几点说明:
_dash-loading-callback选择器选择其在每一个回调由时间本体元件的端部加入一个div,并且当它完成被除去。_dash-loading-callback。| 归档时间: |
|
| 查看次数: |
11599 次 |
| 最近记录: |