Hello!
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:
print("Start")
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()
self.register_callbacks(app)
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:
self.create_components()
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")
dashboard.app.run_server(debug=True)
Here is the output:
C:\Code\DashSandbox>python app.py
Start
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 http://127.0.0.1:8050/
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
Start
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 http://127.0.0.1:8050/
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?