Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Add optional argument for changing title of JupyterLab tab. #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions extensions/jupyterlab/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -62,6 +67,7 @@ interface DashMessageData {
type: string;
port: string;
url: string;
title: string;
}

function activate(
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions jupyter_dash/jupyter_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def alive():
def run_server(
self,
mode=None, width="100%", height=650, inline_exceptions=None,
jupyterlab_title="",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@litghost apologies for losing track of this PR for so long. If you're still interested in this, it's a great start, just two comments:

  • we can call this kwarg just title, since we already have examples of kwargs here (width and height) that apply only to one mode without including the mode in the name.
  • let's add this to the docstring below, and to the changelog.

If you've moved on and don't want to come back to this, no worries, I'll get this across the finish line.

**kwargs
):
"""
Expand Down Expand Up @@ -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
Expand All @@ -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':
Expand All @@ -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(
Expand Down