Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mckinsey/vizro into dev/dashboard_g…
Browse files Browse the repository at this point in the history
…enerator
  • Loading branch information
lingyielia committed Jul 15, 2024
2 parents 77b8615 + 4af6ec0 commit f648771
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Bug report
description: Something is not working correctly
labels: "Status: Needs triage :mag:, Issue: Bug Report :bug:"
labels: "Needs triage :mag:, Bug Report :bug:"

body:
- type: markdown
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Feature request
description: Suggest an idea for this project
labels: "Status: Needs triage :mag:, Issue: Feature Request :nerd_face:"
labels: "Needs triage :mag:, Feature Request :nerd_face:"

body:
- type: markdown
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/general-question.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: General question
description: General questions around Vizro
labels: "Status: Needs triage :mag:, Issue: General Question :question:"
labels: "Needs triage :mag:, General Question :question:"

body:
- type: markdown
Expand Down
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"Package: Vizro-AI :robot:":
"Vizro-AI :robot:":
- changed-files:
- any-glob-to-any-file: ["vizro-ai/**/*"]
2 changes: 1 addition & 1 deletion tools/check_branch_name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

BRANCH_LOCAL=$(git symbolic-ref --short HEAD)
BRANCH_CI=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
REGEX="^(main|(release|feat|bug|docs|qa|dev|demo|ci|tidy|dependabot)\/[^/]+(/[^/]+)*)$"
REGEX="^(main|(release|feat|bug|docs|qa|dev|demo|ci|tidy|dependabot|poc)\/[^/]+(/[^/]+)*)$"

if ! [[ $BRANCH_LOCAL =~ $REGEX ]] && [[ $BRANCH_CI =~ $REGEX ]]; then
echo "Branch name is invalid - please rename your branch following this regex syntax: $REGEX"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->

### Added

- Vizro app itself implements WSGI interface as a shortcut to `app.dash.server`. ([#580](https://github.com/mckinsey/vizro/pull/580))

<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
9 changes: 4 additions & 5 deletions vizro-core/docs/pages/user-guides/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,18 @@ The dashboard application can be launched in a Jupyter environment in `inline`,
)

dashboard = vm.Dashboard(pages=[page])
app = Vizro().build(dashboard)
server = app.dash.server # (1)!
app = Vizro().build(dashboard) # (1)!

if __name__ == "__main__": # (2)!
app.run()
```

1. Expose the underlying Flask app through `app.dash.server`; this will be used by Gunicorn.
1. The Vizro `app` object is a WSGI application that exposes the underlying Flask app; this will be used by Gunicorn.
2. Enable the same app to still be run using the built-in Flask server with `python app.py` for development purposes.

To run using Gunicorn with four worker processes, execute
```bash
gunicorn app:server --workers 4
gunicorn app:app --workers 4
```
in the command line. For more Gunicorn configuration options, refer to [Gunicorn documentation](https://docs.gunicorn.org/).

Expand All @@ -132,6 +131,6 @@ A Vizro app wraps a Dash app, which itself wraps a Flask app. Hence to deploy a
- [Flask deployment documentation](https://flask.palletsprojects.com/en/2.0.x/deploying/)
- [Dash deployment documentation](https://dash.plotly.com/deployment)

In particular, `app = Vizro()` exposes the Flask app through `app.dash.server`. As in the [above example with Gunicorn](#gunicorn), this provides the application instance to a [WSGI](https://werkzeug.palletsprojects.com/en/3.0.x/terms/#wsgi) server.
Internally, `app = Vizro()` contains a Flask app in `app.dash.server`. However, as a convenience, the Vizro `app` itself implements the [WSGI application interface](https://werkzeug.palletsprojects.com/en/3.0.x/terms/#wsgi) as a shortcut to the underlying Flask app. This means that, as in the [above example with Gunicorn](#gunicorn), the Vizro `app` object can be directly supplied to the WSGI server.

[`Vizro`][vizro.Vizro] accepts `**kwargs` that are passed through to `Dash`. This enables you to configure the underlying Dash app using the same [arguments that are available](https://dash.plotly.com/reference#dash.dash) in `Dash`. For example, in a deployment context, you might like to specify a custom `url_base_pathname` to serve your Vizro app at a specific URL rather than at your domain root.
15 changes: 14 additions & 1 deletion vizro-core/src/vizro/_vizro.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import logging
import warnings
from pathlib import Path
from typing import List
from typing import TYPE_CHECKING, Iterable, List

import dash
import flask
Expand All @@ -13,6 +15,10 @@

logger = logging.getLogger(__name__)

if TYPE_CHECKING:
# These are built into wsgiref.types for Python 3.11 onwards.
from _typeshed.wsgi import StartResponse, WSGIEnvironment


class Vizro:
"""The main class of the `vizro` package."""
Expand Down Expand Up @@ -118,6 +124,13 @@ def _pre_build():
if hasattr(model, "pre_build"):
model.pre_build()

def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]:
"""Implements WSGI application interface.
This means you can do e.g. gunicorn app:app without needing to manually define server = app.dash.server.
"""
return self.dash.server(environ, start_response)

@staticmethod
def _reset():
"""Private method that clears all state in the `Vizro` app.
Expand Down

0 comments on commit f648771

Please sign in to comment.