如何使用 Dash plotly 添加/创建自定义加载器? [英] How to add/create a custom loader with Dash plotly?

查看:23
本文介绍了如何使用 Dash plotly 添加/创建自定义加载器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的 gif 传递给加载器组件,而不是使用默认数字.有人知道怎么做吗?

I want to pass my gif to the loader component instead of using the default figures. Does anybody know how to do that?

这是我的代码:

dcc.Loading(
    id="loading-1",
    type="default",
    children=html.Div(id="loading-output-1"),
)

我正在尝试完成这样的事情:

and I am trying to accomplish something like this :

dcc.Loading(
    id="loading-1",
    type="assets/dashboard_loader.gif",
    children=html.Div(id="loading-output-1"),
)

有人可以指导我吗?

推荐答案

type 属性指定微调器的外观,但仅限于 dash 核心组件提供的一组值:

The type property specifies what the spinner looks like, but is limited to a set of values dash core components provides:

type(一个值等于:'graph','cube','circle','dot','default';默认'default'):确定哪个微调器显示'graph','之一的属性立方体"、圆"、点"或默认".

type (a value equal to: 'graph', 'cube', 'circle', 'dot', 'default'; default 'default'): Property that determines which spinner to show one of 'graph', 'cube', 'circle', 'dot', or 'default'.

所以你的方法目前是不可能的,但有一个解决方法.

So your approach is currently not possible, but there is a workaround.

默认微调器的 html 结构如下所示:

The html structure of the default spinner looks something like this:

<div class="dash-spinner dash-default-spinner">
  <div class="dash-default-spinner-rect1"></div>
  <div class="dash-default-spinner-rect2"></div>
  <div class="dash-default-spinner-rect3"></div>
  <div class="dash-default-spinner-rect4"></div>
  <div class="dash-default-spinner-rect5"></div>
</div>

.dash-spinner 中的每个矩形 div 都用于默认类型的动画.我们不关心这些矩形或 .dash-spinner 内部的任何东西,因为我们只想要 gif 动画.

Each of these rectangle divs inside .dash-spinner are used for the default type animation. We don't care about these rectangles or anything that's inside of .dash-spinner, because we only want the gif animation.

所以我们可以在这里做的是隐藏所有 .dash-spinner 子元素并为 .dash-spinner 添加动画背景.

So what we could do here is to hide all .dash-spinner children and add an animated background to .dash-spinner.

我们可以用 css 做到这一点

We can do so with css

.dash-spinner {
  background-image: url("http://i.stack.imgur.com/SBv4T.gif");
  background-size: contain;
  background-repeat: no-repeat;
}

.dash-spinner * {
  display: none !important;
}

如需包含 css,请参阅文档此处.

For including css see the documentation here.

基于文档此处中给出的示例的最小且可重复的示例:

Minimal and reproducible example based on the example given in the documentation here:

from dash import Dash
import time
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output


app = Dash(__name__)
app.layout = html.Div(
    children=[
        html.H3("Edit text input to see loading state"),
        dcc.Input(id="loading-input-1", value="Input triggers local spinner"),
        dcc.Loading(
            id="loading-1", type="default", children=html.Div(id="loading-output-1")
        ),
    ],
)


@app.callback(
    Output("loading-output-1", "children"),
    Input("loading-input-1", "value"),
    prevent_initial_call=True,
)
def input_triggers_spinner(value):
    time.sleep(2)
    return value


if __name__ == "__main__":
    app.run_server()


Gif 取自此相关答案此处.

这篇关于如何使用 Dash plotly 添加/创建自定义加载器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆