Repository: plotly/dash

Issue:
[BUG]  _force_eager_loading depends on import/instantiation order
<details>
 <summary>click for obligatory `pip list | grep dash`</summary>

| package  | version |
| ------------- | ------------- |
| dash               |                1.5.0      |
| dash-auth        |                  1.2.0    |   
| dash-bio           |                0.1.1      | 
| dash-bio-utils    |                 0.0.2     |  
| dash-canvas       |                 0.0.11  |    
| dash-core-components    |           1.4.0     |  
| dash-cytoscape           |          0.0.5       |
| dash-dangerously-set-inner-html |   0.0.2 |      
| dash-daq              |             0.1.0      | 
| dash-design-kit         |           1.3.0       /home/plotly/Workspace/dash-design-kit         |
| dash-design-kit-docs     |          1.3.0       |
| dash-enterprise-auth       |        0.0.2       |
| dash-extra-components     |         0.0.1    |   
| dash-html-components       |        1.0.1      | 
| dash-renderer              |        1.2.0   |
| dash-table                |         4.5.0       |

</details>

In `dash v1.5.0`, instantiating or importing an "app" (i.e. `app = dash.Dash(__name__)`) before importing a package with `_force_eager_loading = True` defined in its `__init__.py` file will still result in lazy loading. Expected behavior is that eager loading will be forced, as implied by the flag name. This can result in missing dependencies, e.g. `plotly.js`: 

![image](https://user-images.githubusercontent.com/9068290/67799921-abeecd00-fa5c-11e9-82cd-607a44b1cb39.png)

Confirmed as reproducible by @Marc-Andre-Rivet 


Discussion:

Resolving patch:
diff --git a/dash/dash.py b/dash/dash.py
--- a/dash/dash.py
+++ b/dash/dash.py
@@ -229,12 +229,6 @@ def __init__(
         plugins=None,
         **obsolete
     ):
-        # Apply _force_eager_loading overrides from modules
-        for module_name in ComponentRegistry.registry:
-            module = sys.modules[module_name]
-            eager = getattr(module, '_force_eager_loading', False)
-            eager_loading = eager_loading or eager
-
         for key in obsolete:
             if key in ["components_cache_max_age", "static_folder"]:
                 raise exceptions.ObsoleteKwargException(
@@ -272,6 +266,7 @@ def __init__(
             assets_external_path=get_combined_config(
                 "assets_external_path", assets_external_path, ""
             ),
+            eager_loading=eager_loading,
             include_assets_files=get_combined_config(
                 "include_assets_files", include_assets_files, True
             ),
@@ -1434,6 +1429,16 @@ def _validate_layout(self):
             component_ids.add(component_id)
 
     def _setup_server(self):
+        # Apply _force_eager_loading overrides from modules
+        eager_loading = self.config.eager_loading
+        for module_name in ComponentRegistry.registry:
+            module = sys.modules[module_name]
+            eager = getattr(module, '_force_eager_loading', False)
+            eager_loading = eager_loading or eager
+
+        # Update eager_loading settings
+        self.scripts.config.eager_loading = eager_loading
+
         if self.config.include_assets_files:
             self._walk_assets_directory()
 


Test patch: