Skip to content

Add separate init_app function for providing the flask app #739

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

Merged
merged 6 commits into from
May 28, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def __init__(
components_cache_max_age=None,
show_undo_redo=False,
plugins=None,
defer_app=False,
**kwargs):

# Store some flask-related parameters for use in init_app()
Expand All @@ -131,7 +130,13 @@ def __init__(
self._assets_url_path = assets_url_path

# allow users to supply their own flask server
self.server = server or Flask(name, static_folder=static_folder)
if server:
if isinstance(server, Flask):
self.server = server
else:
self.server = Flask(name, static_folder=static_folder)
else:
self.server = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the choice of True (auto), False (defer) and Flask(...) (use existing) but then the default value should be updated to True. I'd also say, given that we're now accepting multiple value types for server, that we should explicitly throw an error if we get neither a Flask nor a bool - I know @chriddyp likes making specific types in exceptions.py, but I'd be fine with just something like ValueError

So something like:

if isinstance(server, bool):
    self.server = Flask(...) if server else None
elif isinstance(server, Flask):
    self.server = server
else:
    raise ValueError('server must be a Flask app or a boolean')


url_base_pathname, routes_pathname_prefix, requests_pathname_prefix = \
pathname_configs(
Expand Down Expand Up @@ -212,7 +217,7 @@ def __init__(
for plugin in plugins:
plugin.plug(self)

if not defer_app:
if self.server is not None:
self.init_app()

def init_app(self, app=None):
Expand Down