如何使用 Dash plotly 添加/创建自定义加载器?

2023-09-28Python开发问题
7

本文介绍了如何使用 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 添加/创建自定义加载器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11