I've got a Python module that supports a Jupyter frontend using Ipywidgets. This works fine in Jupyter Notebook, but fails silently in Jupyterlab, because they apparently don't allow arbitrary Javascript anymore. There is an Ipywidgets extension for Jupyterlab, but it wouldn't be obvious to the user that they need to do that, so I'd like to display a message if the current context is a Jupyterlab environment and the extension isn't installed. Something like this:
def isIpy():
try:
__IPYTHON__
return True
except NameError: return False
if is_ipy():
if <is_jupyterlab()> and not <has_widgets_extension()>: print('Use \'jupyter labextension install @jupyter-widgets/jupyterlab-manager\' to install the widgets extension')
else: launchIpyWidgets() #This works fine
else: launchTkinterWidgets() #This also works fine
Alternatively – and perhaps preferably – I could place a check in the widget display:
from IPython.display import display
from ipywidgets import interactive, Layout, Accordion, HBox, VBox, HTML, Label, Button, FloatProgress
postinstruct = Label(value='After setting parameter values, run launchPlots() or start() to start the model.')
display(postinstruct)
if <failed to display>: print('Use \'jupyter labextension install @jupyter-widgets/jupyterlab-manager\' to install the widgets extension')
The problem being that, in Jupyterlab, it won't return an error, or display the widget; it'll just display the text Label(value='Use…')
.
Any idea how to reliably check either of these things?