首页 > 解决方案 > 如何在 Dash 组件页面处于加载状态时更改默认的“Loading...”消息?

问题描述

我尝试了DCC Loading component并且还尝试了CSS在组件处于加载状态时禁用屏幕上默认的“正在加载..”文本的方法。它根本不起作用。请建议我一种将默认加载消息更改为带有CSSin的加载器的方法Plotly's Dash

这是dashapp.py将作为登录页面加载的文件:

from dash import Dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html 
from dash.dependencies import Input, Output, State
from config import appserver
import time

external_stylesheets = [dbc.themes.YETI,'./frontend/static/stylesheet.css']

dashapp = Dash(__name__, server = appserver,external_stylesheets=external_stylesheets,\
url_base_pathname='/application/', title='Home Page', assets_url_path='assets')

dashapp.css.config.serve_locally = True

dashapp.layout = html.Div([
    html.H1('Hi Welcome to Dash-Flask integration app!'),
], id="child-process")

if __name__=='__main__':
    dashapp.run_server(debug=True)

样式表CSS存在于目录中:./frontend/static/.
我使用CSS样式表来覆盖默认加载行为,如下所示:

*[data-dash-is-loading="true"]{
  visibility: hidden;
}
*[data-dash-is-loading="true"]::before{
  content: "Loading...";
  display: inline-block;
  color: magenta;
  visibility: visible;
}

标签: plotly-dashplotly-python

解决方案


通过在目录下添加以下 CSS 文件/assets/style.css,我的问题得到了解决。

/* assets/style.css */
._dash-loading {
  margin: auto;
  color: transparent;
  width: 0;
  height: 0;
  text-align: center;
}

._dash-loading::after {
  content: '';
  display: inline-block;
  width: 2rem;
  height: 2rem;
  color: black;
  vertical-align: text-bottom;
  border: 0.25em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  -webkit-animation: spinner-border 0.75s linear infinite;
  animation: spinner-border 0.75s linear infinite;
  margin-top: 2rem;
}

推荐阅读