From 66f0045378d2c283752b4de664f1a84508fe84b9 Mon Sep 17 00:00:00 2001 From: Anamaria Todor Date: Sun, 9 Oct 2022 22:23:26 +0200 Subject: [PATCH 1/5] Added route and request prefix. --- explainerdashboard/dashboards.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/explainerdashboard/dashboards.py b/explainerdashboard/dashboards.py index b415485..25a639d 100644 --- a/explainerdashboard/dashboards.py +++ b/explainerdashboard/dashboards.py @@ -366,6 +366,8 @@ def __init__(self, external_stylesheets:List[str]=None, server:bool=True, url_base_pathname:str=None, + routes_pathname_prefix:str=None, + requests_pathname_prefix:str=None, responsive:bool=True, logins:List[List[str]]=None, port:int=8050, @@ -933,6 +935,8 @@ def _get_dash_app(self): external_stylesheets=self.external_stylesheets, assets_ignore=assets_ignore, url_base_pathname=self.url_base_pathname, + routes_pathname_prefix=self.routes_pathname_prefix, + requests_pathname_prefix=self.requests_pathname_prefix, meta_tags=meta_tags) elif self.mode in ['inline', 'jupyterlab', 'external']: app = JupyterDash(__name__, From f153ab1418b46ef94184f643afeee32f01ef6f14 Mon Sep 17 00:00:00 2001 From: Anamaria Todor Date: Wed, 30 Nov 2022 15:03:30 +0100 Subject: [PATCH 2/5] Testing with 3.7 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b41272f..84fb513 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ "Intended Audience :: Education", "Topic :: Scientific/Engineering :: Artificial Intelligence"], install_requires=requirements, - python_requires='>=3.8', + python_requires='>=3.7', entry_points={ 'console_scripts': [ 'explainerdashboard = explainerdashboard.cli:explainerdashboard_cli', From 2569ef0178575e9552dd14b6e95fbf605009db92 Mon Sep 17 00:00:00 2001 From: Anamaria Todor Date: Thu, 8 Dec 2022 15:32:59 +0100 Subject: [PATCH 3/5] Rvert back to 3.8 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 84fb513..b41272f 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ "Intended Audience :: Education", "Topic :: Scientific/Engineering :: Artificial Intelligence"], install_requires=requirements, - python_requires='>=3.7', + python_requires='>=3.8', entry_points={ 'console_scripts': [ 'explainerdashboard = explainerdashboard.cli:explainerdashboard_cli', From 894088d7da2063be3bc43bec372e01fd41ec2ae0 Mon Sep 17 00:00:00 2001 From: Oege Dijk Date: Tue, 13 Dec 2022 20:54:24 +0100 Subject: [PATCH 4/5] adds dash_kwargs to ExplainerDashboard --- explainerdashboard/dashboards.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/explainerdashboard/dashboards.py b/explainerdashboard/dashboards.py index 25a639d..5e42b4b 100644 --- a/explainerdashboard/dashboards.py +++ b/explainerdashboard/dashboards.py @@ -14,7 +14,7 @@ import json import inspect import requests -from typing import List, Union +from typing import List, Union, Dict from pathlib import Path from copy import copy, deepcopy import warnings @@ -368,6 +368,7 @@ def __init__(self, url_base_pathname:str=None, routes_pathname_prefix:str=None, requests_pathname_prefix:str=None, + dash_kwargs:Dict=None, responsive:bool=True, logins:List[List[str]]=None, port:int=8050, @@ -452,6 +453,10 @@ def __init__(self, server is created. url_base_pathname (str): url_base_pathname for dashboard, e.g. "/dashboard". Defaults to None. + routes_pathname_prefix(str): prefix to route. E.g. on sagemaker you would set this to '/' + requests_pathname_prefix(str): on sagemaker you would set this to f'/jupyter/default/proxy/{port}/' + dash_kwargs (dict): dictionary of additional dash key word arguments that + you would like to pass to the dash.Dash instance as **dash_kwargs. responsive (bool): make layout responsive to viewport size (i.e. reorganize bootstrap columns on small devices). Set to False when e.g. testing with a headless browser. Defaults to True. @@ -501,6 +506,9 @@ def __init__(self, "mode='external', mode='inline' or mode='jupyterlab' " "to keep the notebook interactive while the dashboard " "is running...", flush=True) + + if self.dash_kwargs is None: + self.dash_kwargs = {} if self.bootstrap is not None: bootstrap_theme = self.bootstrap if isinstance(self.bootstrap, str) else dbc.themes.BOOTSTRAP @@ -937,12 +945,14 @@ def _get_dash_app(self): url_base_pathname=self.url_base_pathname, routes_pathname_prefix=self.routes_pathname_prefix, requests_pathname_prefix=self.requests_pathname_prefix, - meta_tags=meta_tags) + meta_tags=meta_tags, + **self.dash_kwargs) elif self.mode in ['inline', 'jupyterlab', 'external']: app = JupyterDash(__name__, external_stylesheets=self.external_stylesheets, assets_ignore=assets_ignore, - meta_tags=meta_tags) + meta_tags=meta_tags, + **self.dash_kwargs) else: raise ValueError(f"mode=={self.mode} but should be in " "{'dash', 'inline', 'juypyterlab', 'external'}") From 31609f2e32d03ba6320ed791faf3118c7f137449 Mon Sep 17 00:00:00 2001 From: Oege Dijk Date: Tue, 13 Dec 2022 21:09:08 +0100 Subject: [PATCH 5/5] adds sagemaker option to ExplainerDashboard.run --- explainerdashboard/dashboards.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/explainerdashboard/dashboards.py b/explainerdashboard/dashboards.py index 5e42b4b..0bc97de 100644 --- a/explainerdashboard/dashboards.py +++ b/explainerdashboard/dashboards.py @@ -967,7 +967,7 @@ def flask_server(self): print("Warning: in production you should probably use mode='dash'...") return self.app.server - def run(self, port=None, host='0.0.0.0', use_waitress=False, mode=None, **kwargs): + def run(self, port:int=None, host:str='0.0.0.0', use_waitress:bool=False, mode:str=None, sagemaker:bool=False, **kwargs): """Start ExplainerDashboard on port Args: @@ -983,6 +983,9 @@ def run(self, port=None, host='0.0.0.0', use_waitress=False, mode=None, **kwargs Overrides self.mode, in which case the dashboard will get rebuilt before running it with the right type of dash server. (dash.Dash or JupyterDash). Defaults to None (i.e. self.mode) + sagemaker (bool): if True then fills in routes_pathname_prefix='/', + and equests_pathname_prefix=f'/jupyter/default/proxy/{port}/' so + that the dashboard can run in AWS Sagemaker Defaults to None.self.port defaults to 8050. Raises: @@ -1005,6 +1008,12 @@ def run(self, port=None, host='0.0.0.0', use_waitress=False, mode=None, **kwargs "with mode='dash'. Rebuilding dashboard before launch:", flush=True) app = ExplainerDashboard.from_config( self.explainer, self.to_yaml(return_dict=True), mode='dash').app + elif sagemaker: + app = ExplainerDashboard.from_config( + self.explainer, self.to_yaml(return_dict=True), + routes_pathname_prefix='/', + requests_pathname_prefix=f'/jupyter/default/proxy/{port}/', + ).app else: app = self.app