Dash module takes too long to load on Windows 10

I have been using Dash to make data visualization apps that run locally. Recently, I’ve noticed that the dash module takes too long to load (>1 minute) for the app, which was much faster before. There have been some changes in my configuration:

  • I recently updated my OS to Windows 10
  • I upgraded dash to 1.4.1

I’m running a simple script as follows, that basically just takes one of the first examples given in the user guide and wraps it in a class structure:


import time

t0 = time.time()
import dash
print(f"Time to load dash: {time.time()-t0}")

t0 = time.time()
import dash_core_components as dcc
print(f"Time to load dcc: {time.time()-t0}")

t0 = time.time()
import dash_html_components as html
print(f"Time to load html: {time.time()-t0}")

t0 = time.time()
from dash.dependencies import State, Input, Output
print(f"Time for dependencies: {time.time()-t0}")

t0 = time.time()

class Dashboard:

    def __init__(self, app=None):

        self.app = app
        self.components = {}

        self._components_created = False

        self.app.layout = self.create_layout()

    def create_components(self):
        """Should be called once to create all the components.
        (Automatically called during init)

        self.components["input"] = dcc.Input(id='my-id', value='initial value', type='text')
        self.components["output"] = html.Div(id='my-div')

        self._components_created = True

    def create_layout(self):
        """Should be called every time the app layout needs to be redrawn.
        (Called for the first time during init)

        if not self._components_created:

        return html.Div([self.components["input"], self.components["output"]])

    def register_callbacks(self, app):
        """All callback definitions go here.
        (Automatically called during init)
        @app.callback(Output(component_id='my-div', component_property='children'),
                      [Input(component_id='my-id', component_property='value')])
        def update_output_div(input_value):
            return 'You\'ve entered "{}"'.format(input_value)

print(f"Time for class creation: {time.time()-t0}")

# %%

if __name__ == "__main__":

    print("Starting server")

    app = dash.Dash(__name__)
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    app.config["suppress_callback_exceptions"] = True

    print("Loading Dashboard")
    dashboard = Dashboard(app=app)

    print("Running Dashboard")

Here is the output:

C:\Code\DashSandbox>python app.py
Time to load dash: 57.21042799949646
Time to load dcc: 0.6083998680114746
Time to load html: 3.198499917984009
Time for dependencies: 0.0
Time for class creation: 0.0
Starting server
Loading Dashboard
Running Dashboard
Running on
Debugger PIN: 807-361-190
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
Time to load dash: 58.59530210494995
Time to load dcc: 0.6702072620391846
Time to load html: 3.447148084640503
Time for dependencies: 0.0
Time for class creation: 0.0
Starting server
Loading Dashboard
Running Dashboard
Running on
Debugger PIN: 632-510-858

Two observations:

  • Module dash is taking too long to load (~60s each time)
  • When I run with debug=True, the whole script is ran twice, which doubles the delay.

My system hardware is pretty good (core i7, 16gb RAM), and previously it used to take me <10s to start the app. So I’m wondering what could be happening. Any ideas?

I just ran the same file on my Macbook, and it took <2s to load dash! So it has definitely something to do with the setup. However, no other python modules are showing any significant difference. I tried comparing load times for pandas, numpy etc., as well as some of my private modules. Nothing shows a difference as large as that for dash.

Has anyone encountered something similar? Any pointers would be appreciated!


1 Like

Yikes, painful. On my system the plotly package is responsible for the bulk of the time of import dash. Just to help narrow it down, can you try timing import plotly followed by timing import dash in the same session?

Is it better if you create a fresh venv and install only dash in it?

And to fix it… only thing that occurs to me, unless we can pinpoint the cause, is to uninstall and reinstall whichever one of these is slow.

(BTW while I notice: in Dash v1.x serve_locally is the default so you can omit those lines, and suppress_callback_exceptions can go in the constructor: app = dash.Dash(__name__, suppress_callback_exceptions=True)

1 Like

Thanks for your response!

I tried your suggestion, and you are right, it is actually plotly that’s taking the bulk of the load time. Installing dash in its own environment didn’t change anything, it’s still taking too long to load.

It’s effectively stopped my dash development right now, so if there are any other ideas, I’m all ears! I’m wondering, once a package is installed, what factors would affect its load time in python?

OK good, we’re making progress… What version of plotly do you have? That package is not automatically upgraded when you upgrade dash. @jmmease do you have any thoughts about what piece of this could be bogging down, and how we could address it?

My plotly version was 4.1.1. I upgraded it to 4.2.1 just to make sure, but it’s still taking me ~55s to load that module.

So now at least I can say that the issue is with the plotly module, and not dash. Installing plotly in its own env doesn’t improve things either :frowning_face: