Skip to content

Commit

Permalink
hub: option to configure static route in base route (#208)
Browse files Browse the repository at this point in the history
* hub: option to configure static route in base route

* SHAP dependence: minor fixup for label
  • Loading branch information
Achim Gädke committed Apr 28, 2022
1 parent 6306e32 commit 35ad001
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion explainerdashboard/dashboard_components/shap_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def layout(self):
value=self.col)
], md=3), self.hide_col),
make_hideable(dbc.Col([
html.Label('Color feature:', id='shap-dependence-color-col-label-'+self.name),
dbc.Label('Color feature:', id='shap-dependence-color-col-label-'+self.name),
dbc.Tooltip("Select feature to color the scatter markers by. This "
"allows you to see interactions between various features in the graph.",
target='shap-dependence-color-col-label-'+self.name),
Expand Down
20 changes: 13 additions & 7 deletions explainerdashboard/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,9 @@ def __init__(self, dashboards:List[ExplainerDashboard], title:str="ExplainerHub"
dbs_open_by_default:bool=False, port:int=8050,
min_height:int=3000, secret_key:str=None, no_index:bool=False,
bootstrap:str=None, fluid:bool=True, base_route:str="dashboards",
index_to_base_route:bool=False, max_dashboards:int=None,
index_to_base_route:bool=False,
static_to_base_route:bool=False,
max_dashboards:int=None,
add_dashboard_route:bool=False, add_dashboard_pattern:str=None, **kwargs):
"""
Expand Down Expand Up @@ -1108,6 +1110,8 @@ def __init__(self, dashboards:List[ExplainerDashboard], title:str="ExplainerHub"
Defaults to "dashboards".
index_to_base_route (bool, optional): Dispatches Hub to "/base_route/index" instead of the default
"/" and "/index". Useful when the host root is not reserved for the ExplainerHub
static_to_base_route(bool, optional): Dispatches Hub to "/base_route/static" instead of the default
"/static". Useful when the host root is not reserved for the ExplainerHub
max_dashboards (int, optional): Max number of dashboards in the hub. Defaults to None
(for no limitation). If set and you add an additional dashboard, the
first dashboard in self.dashboards will be deleted!
Expand Down Expand Up @@ -1150,7 +1154,9 @@ def __init__(self, dashboards:List[ExplainerDashboard], title:str="ExplainerHub"
self.db_users = db_users if db_users is not None else {}
self._validate_users_file(self.users_file)

self.app = Flask(__name__)
static_url_path = f"/{base_route}/static" if static_to_base_route else None
self.app = Flask(__name__, static_url_path=static_url_path)

if secret_key is not None:
self.app.config['SECRET_KEY'] = secret_key
SimpleLogin(self.app, login_checker=self._validate_user)
Expand Down Expand Up @@ -1943,10 +1949,10 @@ def _hub_page(self, route, static=False):
dbs = [(f"{db.name}.html", db.title) for db in self.dashboards]
else:
page = f"""
<script type="text/javascript" src="/static/jquery-3.5.1.slim.min.js"></script>
<script type="text/javascript" src="/static/bootstrap.min.js"></script>
<link type="text/css" rel="stylesheet" href="{'/static/bootstrap.min.css' if self.bootstrap is None else self.bootstrap}"/>
<link rel="shortcut icon" href="/static/favicon.ico">
<script type="text/javascript" src=f"{self.app.static_url_path}/jquery-3.5.1.slim.min.js"></script>
<script type="text/javascript" src=f"{self.app.static_url_path}/bootstrap.min.js"></script>
<link type="text/css" rel="stylesheet" href="{f'{self.app.static_url_path}/bootstrap.min.css' if self.bootstrap is None else self.bootstrap}"/>
<link rel="shortcut icon" href=f"{self.app.static_url_path}/favicon.ico">
"""
dbs = [(f"/{self.base_route}/_{db.name}", db.title) for db in self.dashboards]

Expand Down Expand Up @@ -2049,7 +2055,7 @@ def add_dashboard():
dashboard_path = self.add_dashboard_pattern.format(dashboard_path)
if dashboard_path.endswith(".yaml") and Path(dashboard_path).exists():
db = ExplainerDashboard.from_config(dashboard_path)
dashboard_name = self.add_dashboard(db, bootstrap="/static/bootstrap.min.css")
dashboard_name = self.add_dashboard(db, bootstrap=f"{self.app.static_url_path}/bootstrap.min.css")
return redirect(f"/dashboards/_{dashboard_name}", code=302)
except:
print("ERROR: Failed to add dashboard!", flush=True)
Expand Down

0 comments on commit 35ad001

Please sign in to comment.