Skip to content

Commit

Permalink
Include button for launching jupyterlab layout in repr (#7218)
Browse files Browse the repository at this point in the history
This is an experimental UI element to help ease dashboard setup in a JupyterLab environment. 

This requires dask-labextension 6.0.0
  • Loading branch information
Ian Rose authored Nov 6, 2022
1 parent 821ecd8 commit 17156e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions distributed/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
from contextlib import contextmanager, suppress
from contextvars import ContextVar
from functools import partial
from importlib.metadata import PackageNotFoundError, version
from numbers import Number
from queue import Queue as pyQueue
from typing import Any, ClassVar, Coroutine, Literal, Sequence, TypedDict

from packaging.version import parse as parse_version
from tlz import first, groupby, keymap, merge, partition_all, valmap

import dask
Expand Down Expand Up @@ -1146,6 +1148,12 @@ def __repr__(self):
return f"<{self.__class__.__name__}: No scheduler connected>"

def _repr_html_(self):
try:
dle_version = parse_version(version("dask-labextension"))
JUPYTERLAB = False if dle_version < parse_version("6.0.0") else True
except PackageNotFoundError:
JUPYTERLAB = False

scheduler, info = self._get_scheduler_info()

return get_template("client.html.j2").render(
Expand All @@ -1155,6 +1163,7 @@ def _repr_html_(self):
cluster=self.cluster,
scheduler_file=self.scheduler_file,
dashboard_link=self.dashboard_link,
jupyterlab=JUPYTERLAB,
)

def start(self, **kwargs):
Expand Down
6 changes: 6 additions & 0 deletions distributed/widgets/templates/client.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@

</table>

{% if jupyterlab %}
<button style="margin-bottom: 12px;" data-commandlinker-command="dask:populate-and-launch-layout" data-commandlinker-args='{"url": "{{ dashboard_link }}" }'>
Launch dashboard in JupyterLab
</button>
{% endif %}

{% if scheduler is none %}
<p>No scheduler connected.</p>
{% elif cluster %}
Expand Down

0 comments on commit 17156e9

Please sign in to comment.