7

When Python code is called from a notebook, is it possible to determine whether the notebook is the old notebook vs JupyterLab?

The context behind the question is that I want to display some Javascript-enabled content inline inside the notebook. For regular notebooks, I have all kinds of goodies available (require.js, ability to execute scripts, access to Jupyter.notebook.kernel.execute, etc). In JupyterLab, all of those have been removed for the sake of security.

I'm not questioning the change in JupyterLab, but I do need to determine if those "Javascript goodies" are available or not. If they are not, I will write a temporary html page and open a webbrowser pointing to it -- not quite as nice, but it will do until I decide to write a lab extension and users decide to install it.

So, how do I tell if I'm running within a regular notebook vs lab?

The challenges I run into with potential solutions are:

  1. Anything I execute in Javascript using display(Javascript(...)) is run asynchronously after my Python code returns. So I can't simply write if call_javascript() == 'notebook' or something.
  2. If I allow for the asynchronous nature of Javascript and pass a callback, that only works for the plain notebook. There is no way for JupyterLab to call me back.
jkitchen
  • 900
  • 11
  • 16
  • Does this answer your question? [Python check if jupyter notebook or lab is running](https://stackoverflow.com/questions/50915913/python-check-if-jupyter-notebook-or-lab-is-running) – Trenton McKinney Aug 31 '20 at 22:13
  • 2
    @TrentonMcKinney That link does attempt to answer the same question I have. The answers, unfortunately, appear to only work on older versions of IPython. – jkitchen Aug 31 '20 at 22:22

0 Answers0