diff --git a/extensions/jupyterlab/src/index.ts b/extensions/jupyterlab/src/index.ts index 1b26f65..44ae53a 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); @@ -119,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 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(