I’ve designed a dashboard in a Jupyter notebook (using ipywidgets) that selects a file, sends it to an analysis service, returns the result to the notebook and print to result to an output inside the notebook. However when running the same notebook in a Jupyter lab notebook, the output is printed to the notebook log console rather than a notebook cell. As I’m unable to expose the dashboard I’ve extracted a snipped from the code:
# The function to run
files = file_dd.value
# The files are read and submitted to the service
# Dashboard button callback
Can anyone tell me how to overcome this issue so I can get the output printed inside the Jupyterlab notebook?
Is your JupyterLab install and packages being used here all 100% updated? If that is the case, I think you aren’t connecting properly your widget
out back to the notebook. You cannot just use print with widgets. For debugging you can and JupyterLab trying to handle not 100% proper channeling is what you are seeing; however, to not get what you are seeing in JupyterLab, you need to handle that properly and link it to an
output area. I think this reply by @jasongrout is advice for a similar situation, especially the last line. Obviously the specifics are different because you aren’t trying to capture markdown, just text, but you need to link it back to a display of an output widget in the widget layout.
Specifically, I think this example code in cell #2 and #3 point to what you need to rework your function to do. You need to add in the context manager to your
run_service function. To do it like that, you need to have assigned your
widgets.Output() somewhere, too. I think my comment here as part of that chain is pertinent to this. Presently, the Jupyter notebook classic interface is a little more forgiving when not properly handling widget output. Importantly, you’ll have more resilent code if you update to the more modern way widgets output is handled; I suspect the notebook classic interface won’t be as forgiving when the newer version of what is presently the classic interface has the similar underlying machinery as JupyterLab, which is the plan going forward.