plotly / plotly/dash

provide loading Indicator during plotly rendering

Open
#2,690 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

I have created a simple dash app, which renders a scatter plot using plotly express, I have used the dcc.Loading to wrap the component which displays the plot upon a simple button click.

But during the initial rendering the indicator stops displaying once the component is ready with its data, but the plot is not yet rendered and displayed to the user.

Is there any way to show a loading spinner or any loading indicator which can be displayed until the plot is rendered? Or anything within the dcc.Graph component which can show this loading indicator until the plot is rendered completly

I have searched around the plotly documentation and not seem find anything suitable.

The CSV file being consumed is around 250 mb and the delay after the loading indicator stops and the plot to render is around a second or 2, but this might increase once the files being consumed are also increasing in size.

import time
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd
import numpy as np

df = pd.read_csv(
    '2m Sales Records.csv',
    index_col=0)

app = dash.Dash(__name__)

app.layout = html.Div([
    html.Button('Update Plot', id='update-button', n_clicks=0),
    html.Div([
        dcc.Loading(
            id="loading",
            type="default",
            fullscreen=True,
            children=[
                html.Div(id='graph-container')
            ]
        )
    ])
])


@app.callback(
    Output('graph-container', 'children'),
    [Input('update-button', 'n_clicks')]
)
def update_plot(n_clicks):
    x_column = 'Units Sold'
    y_column = 'Total Profit'

    if n_clicks > 0:
        fig = px.scatter(df, x=x_column, y=y_column, title='Scatter Plot')
        fig.update_traces(textposition='top center')

        return dcc.Graph(id='volcano-plot', figure=fig)

    return html.Div()


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

The CSV file with about 2million records:
2m-Sales-Records.zip

Video Sample:

https://github.com/plotly/dash/assets/150319231/07be24af-f482-45cc-903d-2e2d85eece1b

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example with dcc.Loading wrapping the graph-container and returning dcc.Graph, using the provided 2-million-record CSV. Investigate the loading lifecycle around dcc.Graph rendering and determine whether an existing component option supports the requested indicator. Done means the indicator remains visible until the plot is rendered, including with larger data.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.