Giter Site home page Giter Site logo

glsdown / dash-loading-spinners Goto Github PK

View Code? Open in Web Editor NEW
34.0 1.0 2.0 1 MB

Fun and funky spinners for use with Dash apps

Home Page: https://dash-loading-spinners.sproodlebuzz.co.uk/

License: MIT License

Python 4.76% HTML 0.12% JavaScript 95.11%
dash plotly-dash spinners dash-spinners dash-loading-spinners loading-spinners dash-loading dash-spinner dash-loading-spinner

dash-loading-spinners's Introduction

Dash Loading Spinners

Tests PyPI PyPI - License PyPI - Python Version Downloads

This library is designed for use with Plotly Dash. The components have all been designed to provide functionality similar to Dash's core Loading component, and will display a loading spinner whilst the underlying children are re-rendering.

The spinners in it have been adapted for use from a number of other existing libraries:

The majority of spinner names have been retained from the originals, but some have been amended where there were name clashes.

More details on the components and usage can be found in our documentation.


Installation

Dash Loading Spinners is available through PyPI, and can be installed with pip:

pip install dash-loading-spinners

Basic Usage

Once installed, you can make use of the components (in their most basic sense) as follows:

import dash
import dash_loading_spinners as dls

app = dash.Dash()

app.layout = dls.Hash()

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

There are a number of attributes which are common across all spinners. These are:

  • id (string; optional): The ID of this component, used to identify dash components in callbacks. The ID needs to be unique across all of the components in an app.
  • children (a list of or a singular dash component, string or number; optional): The children of this component.
  • show_initially (boolean; default True): Whether the Spinner should show on app start-up before the loading state has been determined. Default True.
  • debounce (number; default 0): When using the spinner as a loading spinner, add a time delay (in ms) to the spinner being removed to prevent flickering.
  • fullscreen (boolean; optional): Boolean that determines if the loading spinner will be displayed full-screen or not.
  • fullscreenClassName (string; optional): CSS class names to apply to the container when in fullscreen.
  • fullscreen_style (dict; optional): Defines CSS styles for the container when in fullscreen.

Many spinners additional have properties that can be customised, including colour and size. You can find these on the individual component pages.

Realistically, as part of an application, you will be using them alongside other components and callbacks. Here is an example of what this might look like:

Note: dash-bootstrap-components isn't necessary for dash-loading-spinners to work, but has been included to improve the layout.

# app.py
import dash
import dash_bootstrap_components as dbc
import dash_loading_spinners as dls
from dash import dcc, html, Input, Output

from helpers import get_new_graph

app = dash.Dash(external_stylesheets=[dbc.themes.UNITED])

app.layout = html.Div(
    [
        dbc.Row(
            [
                dbc.Col(
                    html.Div(
                        dbc.Button(
                            "Simulate slow loading component",
                            id="loading-button",
                            className="btn-success",
                            n_clicks=0,
                        )
                    ),
                    md=3,
                ),
                dbc.Col(
                    dls.Hash(
                        dcc.Graph(id="loading-output",),
                        color="#435278",
                        speed_multiplier=2,
                        size=100,
                    ),
                    md=9,
                ),
            ],
        ),
    ]
)


@app.callback(
    Output("loading-output", "figure"), [Input("loading-button", "n_clicks")],
)
def load_output(n):
    # See note below
    return get_new_graph(n)

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

The function get_new_graph in this example is deliberately ambiguous, as it simply acts as a placeholder for any slow-loading component. For completeness, if you wish to use a similar example to the one shown above, you can use the following function:

# helpers.py
import numpy as np
import plotly.graph_objects as go
import time

def get_new_graph(n):
    if n:
        # Simulate slow-loading component
        time.sleep(2)
    # Generate a random scatter plot
    n = (n + 1) * 10
    return go.Figure(
        data=go.Scatter(
            y=np.random.randn(n) * 100,
            mode="markers",
            marker=dict(
                size=16,
                color=np.random.randn(n) * 100,
                colorscale="blues",
                showscale=True,
            ),
        ),
        layout=go.Layout(title="This graph takes ages to re-load"),
    )

dash-loading-spinners's People

Contributors

cfloressuazo avatar glsdown avatar tcbegley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dash-loading-spinners's Issues

[FEATURE] Upload to UNPKG

Is your feature request related to a problem? Please describe.
Thank you for providing the library. We are using this extensible, but we need the app to load the javascripts from a CDN. Most of the plotly extensions we are using are being loaded from UNPKG, but this is the only one that is not present in there and has to be loaded locally, which is not ideal for applications that are accessed worldwide.

Describe the solution you'd like
Is it possible to upload this package including the javascripts to unpkg.com? Specifically this one: dash_loading_spinners.v1_0_0m1697818026.min.js. This should be taken care for when the application is run via app = Dash(....., serve_locally = False)

Describe alternatives you've considered
Loading the file locally, which is not ideal.

Additional context
Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.