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:
- Anything I execute in Javascript using
display(Javascript(...))
is run asynchronously after my Python code returns. So I can't simply writeif call_javascript() == 'notebook'
or something. - 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.