From 18d25abce3f3d4fab0c9248861572244c18cffea Mon Sep 17 00:00:00 2001 From: Ryan Marren Date: Tue, 14 Aug 2018 20:41:37 -0400 Subject: [PATCH 1/5] Change _validate_layout to accept functions that return layouts. --- dash/dash.py | 7 ++++++- tests/test_integration.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 80691b9f8f..4b86c71a83 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -875,10 +875,15 @@ def _validate_layout(self): 'Make sure to set the `layout` attribute of your application ' 'before running the server.') + if callable(self.layout): + to_validate = self.layout() # pylint: disable=not-callable + else: + to_validate = self.layout + layout_id = getattr(self.layout, 'id', None) component_ids = {layout_id} if layout_id else set() - for component in self.layout.traverse(): + for component in to_validate.traverse(): component_id = getattr(component, 'id', None) if component_id and component_id in component_ids: raise exceptions.DuplicateIdError( diff --git a/tests/test_integration.py b/tests/test_integration.py index 7826de6b24..bec9bbd1db 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -12,7 +12,7 @@ import time from dash.dependencies import Input, Output -from dash.exceptions import PreventUpdate +from dash.exceptions import PreventUpdate, NoLayoutException from .IntegrationTests import IntegrationTests from .utils import assert_clean_console, invincible, wait_for @@ -482,3 +482,14 @@ def test_external_files_init(self): (("//script[@src='{}']", x) for x in js_urls), (("//link[@href='{}']", x) for x in css_urls)): self.driver.find_element_by_xpath(fmt.format(url)) + + def test_func_layout_accepted(self): + + app = dash.Dash() + + def create_layout(): + return html.Div('Hello World') + app.layout = create_layout + + self.startServer(app) + time.sleep(0.5) From 8e34d46ce18b263f6c150e00cce97a59d199cfcc Mon Sep 17 00:00:00 2001 From: Ryan Marren Date: Fri, 17 Aug 2018 18:37:13 -0400 Subject: [PATCH 2/5] :camel: --- dash/dash.py | 5 +---- tests/test_integration.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 4b86c71a83..d2eb28bc00 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -875,10 +875,7 @@ def _validate_layout(self): 'Make sure to set the `layout` attribute of your application ' 'before running the server.') - if callable(self.layout): - to_validate = self.layout() # pylint: disable=not-callable - else: - to_validate = self.layout + to_validate = self._layout_value() layout_id = getattr(self.layout, 'id', None) diff --git a/tests/test_integration.py b/tests/test_integration.py index bec9bbd1db..f4024af79e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -12,7 +12,7 @@ import time from dash.dependencies import Input, Output -from dash.exceptions import PreventUpdate, NoLayoutException +from dash.exceptions import PreventUpdate from .IntegrationTests import IntegrationTests from .utils import assert_clean_console, invincible, wait_for From 4611b7b4472b12c997440cbf4f00976db63c5f71 Mon Sep 17 00:00:00 2001 From: Ryan Marren Date: Sun, 26 Aug 2018 15:20:52 -0400 Subject: [PATCH 3/5] Bump changelog and version. --- CHANGELOG.md | 4 ++++ dash/version.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 026256670d..7fcf7183bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.26.1 - 2018-08-26 +## Fixed +- Fix bug in `_validate_layout` which would not let a user set `app.layout` to be a function that returns a layout [(fixes #334)](https://github.com/plotly/dash/issues/334). [#336](https://github.com/plotly/dash/pull/336) + ## 0.26.0 - 2018-08-20 ## Added - Added `assets_ignore` init keyword, regex filter for the assets files. [#318](https://github.com/plotly/dash/pull/318) diff --git a/dash/version.py b/dash/version.py index 826d20e8b6..f96e1c6bed 100644 --- a/dash/version.py +++ b/dash/version.py @@ -1 +1 @@ -__version__ = '0.26.0' +__version__ = '0.26.1' From 7a97f11d314d93f51694e8f34fb44150f16b0d2f Mon Sep 17 00:00:00 2001 From: Ryan Marren Date: Sun, 26 Aug 2018 15:56:55 -0400 Subject: [PATCH 4/5] Freeze core component versions in requirements.txt --- dev-requirements-py37.txt | 2 +- dev-requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements-py37.txt b/dev-requirements-py37.txt index 0196676c3f..8bccc186c3 100644 --- a/dev-requirements-py37.txt +++ b/dev-requirements-py37.txt @@ -1,4 +1,4 @@ -dash_core_components>=0.4.0 +dash_core_components==0.27.2 dash_html_components>=0.12.0rc3 dash-flow-example==0.0.3 dash-dangerously-set-inner-html diff --git a/dev-requirements.txt b/dev-requirements.txt index b9ad002072..e9575af3e7 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,4 +1,4 @@ -dash_core_components>=0.27.1 +dash_core_components==0.27.2 dash_html_components>=0.12.0rc3 dash_flow_example==0.0.3 dash-dangerously-set-inner-html From ad074af208289a8cbbdb674c4979bc761d82cf5f Mon Sep 17 00:00:00 2001 From: Ryan Marren Date: Sun, 26 Aug 2018 16:07:10 -0400 Subject: [PATCH 5/5] Update dash-core-components version in requirements files to be latest. --- dev-requirements-py37.txt | 2 +- dev-requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements-py37.txt b/dev-requirements-py37.txt index 8bccc186c3..0f3238c436 100644 --- a/dev-requirements-py37.txt +++ b/dev-requirements-py37.txt @@ -1,4 +1,4 @@ -dash_core_components==0.27.2 +dash_core_components>=0.27.2 dash_html_components>=0.12.0rc3 dash-flow-example==0.0.3 dash-dangerously-set-inner-html diff --git a/dev-requirements.txt b/dev-requirements.txt index e9575af3e7..240c7cdbaa 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,4 +1,4 @@ -dash_core_components==0.27.2 +dash_core_components>=0.27.2 dash_html_components>=0.12.0rc3 dash_flow_example==0.0.3 dash-dangerously-set-inner-html