jupyter-widgets / jupyterlab-sidecar

A sidecar output widget for JupyterLab
BSD 3-Clause "New" or "Revised" License
246 stars 39 forks source link

How to programmatically close a sidecar (or all sidecars)? #112

Open matt-gardner opened 2 months ago

matt-gardner commented 2 months ago

In my development loop, I frequently will need to restart the kernel in jupyter, which unlinks sidecars and leaves an unusable pane that I have to close. Reloading sidecars after a kernel restart gives a new tab instead of re-using the old one. Is there a way to easily close old sidecar tabs other than clicking on the X? I have a bunch of sidecar tabs loaded, and it gets cumbersome to click them all closed every time I restart the kernel.

Apologies that I'm using the issue tracker to ask a question; if this functionality exists, I guess this is a documentation request. If it doesn't, it's a feature request :).

brianterry-ama commented 2 months ago

Does Sidecar.close_all() work?

matt-gardner commented 2 months ago

Yes, that works if I remember to run it before restarting the kernel, thanks! It doesn't work if I run it after restarting the kernel. Is there anything that would clean up the tabs after a kernel restart? Then I could put that as the first line in the first cell that I run after a kernel restart, and I wouldn't have to remember to clean up before restarting.