Skip to content

Commit

Permalink
Revert to using separate Dash and JupyterDash classes (#96)
Browse files Browse the repository at this point in the history
* Downgrade Dash to <2.11

* Back to separate Dash/JupyterDash

* Latest versions of Dash work

* Supply Dash classes to unit test
  • Loading branch information
mmwinther authored Aug 22, 2023
1 parent 06a8bbf commit d55a7ea
Show file tree
Hide file tree
Showing 4 changed files with 400 additions and 162 deletions.
16 changes: 10 additions & 6 deletions datadoc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
NAME = "Datadoc"


def build_app() -> Dash:
def build_app(dash_class: type[Dash]) -> Dash:
"""Instantiate the Dash app object, define the layout, register callbacks."""
app = Dash(
app = dash_class(
name=NAME,
title=NAME,
assets_folder=f"{Path(__file__).parent}/assets",
Expand Down Expand Up @@ -78,13 +78,13 @@ def build_app() -> Dash:
return app


def get_app(dataset_path: str | None = None) -> Dash:
def get_app(dataset_path: str | None = None, dash_class: type[Dash] = Dash) -> Dash:
"""Centralize all the ugliness around initializing the app."""
logging.basicConfig(level=logging.INFO, force=True)
logger.info("Datadoc version v%s", get_app_version())
state.current_metadata_language = SupportedLanguages.NORSK_BOKMÅL
state.metadata = DataDocMetadata(dataset_path)
app = build_app()
app = build_app(dash_class)
app.server.register_blueprint(healthz, url_prefix="/healthz")
app.server.config["HEALTHZ"] = {
"live": lambda: True,
Expand All @@ -100,16 +100,20 @@ def main(dataset_path: str | None = None) -> None:
"""Entrypoint when running as a script."""
logging.basicConfig(level=logging.DEBUG, force=True)
logger.info("Starting app with dataset_path = %s", dataset_path)
app = get_app(dataset_path)
if running_in_notebook():
logger.info("Running in notebook")
from jupyter_dash import JupyterDash

JupyterDash.infer_jupyter_proxy_config()
app: JupyterDash = get_app(dataset_path, JupyterDash)
port = pick_random_port()
app.run(jupyter_height=1000, port=port)
app.run_server(mode="jupyterlab", port=port)
logger.info("Server running on port %s", port)
else:
# Assume running in server mode is better (largely for development purposes)
logging.basicConfig(level=logging.DEBUG, force=True)
logger.debug("Starting in development mode")
app = get_app(dataset_path, Dash)
app.run(debug=True, use_reloader=False)


Expand Down
8 changes: 6 additions & 2 deletions datadoc/tests/test_smoke.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Smoke tests."""
import pytest
from dash import Dash
from jupyter_dash import JupyterDash

from datadoc import state
from datadoc.app import build_app
Expand All @@ -7,8 +10,9 @@
from .utils import TEST_PARQUET_FILEPATH


def test_build_app():
@pytest.mark.parametrize("dash_class", [Dash, JupyterDash])
def test_build_app_dash(dash_class: Dash):
state.metadata = DataDocMetadata(str(TEST_PARQUET_FILEPATH))
app = build_app()
app = build_app(dash_class)
assert app.config["name"] == "Datadoc"
assert len(app.callback_map.items()) > 0
Loading

0 comments on commit d55a7ea

Please sign in to comment.