From b4d4827c7d4fb28df0f45af936fd62a0e6a59c8f Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 22 Apr 2021 20:04:31 -0700 Subject: [PATCH 1/2] Add title argument for displaying in JupyterLab tab. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- extensions/jupyterlab/src/index.ts | 12 +++++++++--- jupyter_dash/jupyter_app.py | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/extensions/jupyterlab/src/index.ts b/extensions/jupyterlab/src/index.ts index 1b26f65..d231932 100644 --- a/extensions/jupyterlab/src/index.ts +++ b/extensions/jupyterlab/src/index.ts @@ -22,11 +22,16 @@ class DashIFrameWidget extends Widget { /** * Construct a new DashIFrameWidget. */ - constructor(port: string, url: string) { + constructor(port: string, url: string, title: string) { super(); this.id = port; - this.title.label = `Dash (port: ${port})`; + if(title === "") { + this.title.label = `Dash (port: ${port})`; + } else { + this.title.label = title; + } + this.title.closable = true; this.addClass('jp-dashWidget'); @@ -62,6 +67,7 @@ interface DashMessageData { type: string; port: string; url: string; + title: string; } function activate( @@ -110,7 +116,7 @@ function registerCommTarget( let widget: DashIFrameWidget; if (!widgets.has(msgData.port)) { // Create a new widget - widget = new DashIFrameWidget(msgData.port, msgData.url); + widget = new DashIFrameWidget(msgData.port, msgData.url, msgData.title); widget.update(); widgets.set(msgData.port, widget); diff --git a/jupyter_dash/jupyter_app.py b/jupyter_dash/jupyter_app.py index cb4512e..394d392 100644 --- a/jupyter_dash/jupyter_app.py +++ b/jupyter_dash/jupyter_app.py @@ -149,6 +149,7 @@ def alive(): def run_server( self, mode=None, width="100%", height=650, inline_exceptions=None, + jupyterlab_title="", **kwargs ): """ @@ -321,7 +322,8 @@ def wait_for_app(): if JupyterDash._in_colab: self._display_in_colab(dashboard_url, port, mode, width, height) else: - self._display_in_jupyter(dashboard_url, port, mode, width, height) + self._display_in_jupyter(dashboard_url, port, mode, width, height, + jupyterlab_title) def _display_in_colab(self, dashboard_url, port, mode, width, height): from google.colab import output @@ -332,7 +334,8 @@ def _display_in_colab(self, dashboard_url, port, mode, width, height): print("Dash app running on:") output.serve_kernel_port_as_window(port, anchor_text=dashboard_url) - def _display_in_jupyter(self, dashboard_url, port, mode, width, height): + def _display_in_jupyter(self, dashboard_url, port, mode, width, height, + jupyterlab_title=''): if mode == 'inline': display(IFrame(dashboard_url, width, height)) elif mode == 'external': @@ -346,6 +349,7 @@ def _display_in_jupyter(self, dashboard_url, port, mode, width, height): 'type': 'show', 'port': port, 'url': dashboard_url, + 'title': jupyterlab_title, }) def _config_callback_exception_handling( From f50b4bd15abb35879a002c7f9d5f7f6692d7b4a1 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 22 Apr 2021 21:10:50 -0700 Subject: [PATCH 2/2] Set title.label on show. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- extensions/jupyterlab/src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extensions/jupyterlab/src/index.ts b/extensions/jupyterlab/src/index.ts index d231932..44ae53a 100644 --- a/extensions/jupyterlab/src/index.ts +++ b/extensions/jupyterlab/src/index.ts @@ -125,6 +125,10 @@ function registerCommTarget( widget = widgets.get(msgData.port); } + if(msgData.title !== "") { + widget.title.label = msgData.title + } + if (!widget.isAttached) { // Attach the widget to the main work area // if it's not there