Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide loading Indicator during plotly rendering #2690

Open
Yokogawa-Akshay opened this issue Nov 13, 2023 · 0 comments
Open

provide loading Indicator during plotly rendering #2690

Yokogawa-Akshay opened this issue Nov 13, 2023 · 0 comments
Labels
feature something new P3 backlog

Comments

@Yokogawa-Akshay
Copy link

Yokogawa-Akshay commented Nov 13, 2023

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:

Plot_loading.mp4
@gvwilson gvwilson self-assigned this Jul 25, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added the P3 backlog label Aug 13, 2024
@gvwilson gvwilson changed the title Loading Indicator during plotly rendering provide loading Indicator during plotly rendering Aug 13, 2024
@gvwilson gvwilson added the feature something new label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

No branches or pull requests

2 participants