Is there a way to make IPython Notebook not show the results of the previous session upon opening an existing notebook? It's not a big deal, but it's fairly annoying to have to scroll through the notebook and manually hide all of my results after starting it so I don't have to scroll for five minutes looking for a specific line. Thanks!
To clear all cell numbers and output from an existing notebook in IPython Notebook:
Open the notebook from the IPython Notebook interface by clicking it.
From the menu bar select Cell -> All Output -> Clear.
Related
In addition to loading required modules, in the first cell of the jupyter notebook, I usually load variables (e.g. metadata, tables etc.). So every time when I restart a jupyter notebook, I need to run the 1st cell of the notebook. I know this is not a big issue, but sometimes can be an annoyance. For example, if I would be working at the end of the notebook and need to restart it, I would have to scroll all the way up, run the first cell, and then scroll all the way back to resume the work.
I hope there is a way to automatically run 1st (or any n'th) cell of a jupyter notebook when it is restarted. I wonder if anybody knows if such a functionality exists.
Install jupyter notebook extensions (see here how it is done: https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html ).
Use the Initialization cells extension (https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/init_cell/README.html ).
It allows you to mark one or more cells as 'Initialisation cells' that will run when the notebook is opened or on clicking the (then added) 'initialization button' in the main toolbar.
The cell toolbar selector can be found under View > Cell Toolbar > Initialization Cell.
Not 100% what you are looking for as you need to click an extra button after restarting the notebook. On the other hand, scrolling up and down is avoided and it is an easy fix.
I am currently using Jupyter on a server:
$ python3 --version
Python 3.8.10
$ pip3 list | grep 'jupyter \|nbextensions\|plotly'
jupyter 1.0.0
jupyter-contrib-nbextensions 0.5.1
jupyter-nbextensions-configurator 0.4.1
plotly 5.2.2
My problem is this: I have an .ipynb notebook, with multiple Plotly plots inside, generated by multiple Python code cells.
Then, I have both:
enabled "Initialization cells" on all Python code cells, as per https://stackoverflow.com/a/39666438/6197439 , and saved the notebook
Made a first %%html cell, with JavaScript to re-run all cells on page load, as per https://stackoverflow.com/a/38856870/6197439 , and saved the notebook
Now, the results are like this:
If the kernel corresponding to the .ipynb notebook, has been shut down, and then I open the .ipynb notebook in a new browser tab, then indeed all cells run, and after a some seconds wait, I get the graphs/plots rendered in the page, as I want it
But if now I close that browser tab, and the kernel corresponding to this .ipynb notebook still runs, and I click the .ipynb notebook again so it opens in a new tab, this time the graphs/plots are NOT visible in the page (instead, the corresponding Python code cells are expanded, even if the original saved state is collapsed - where I use the Codefolding nbextension, see collapse cell in jupyter notebook)
Although, at this time, I can call Cell/Run All, and the Plotly plots are generated - but the corresponding code cells remain expanded
So, my question is: is there anything I can do, so that whenever the .ipynb page is opened for the first time, all the Plotly plots are generated - regardless if this is the first page load since the kernel started, or later page loads?
I tried to make interactive in python by using Plotly in Jupyter Notebook.
This is the import code.
import plotly.graph_objects as go
Although I can make the figure successfully. Since I used the server, I do not need to close the jupyter notebook. However, the next time I open the notebook, the image will disappear automatically. I have to restart the Jupiter notebook again and make the figure again.
Who knows how to make the figure appears all the time?
In general, plotly graphs will get cached by Jupyter notebook, in your case it could be due to an access issue to file system of the server. On the other hand, Jupyter provides a way to export the notebook as HTML format.
The option is available in File->download as -> HTML
I am currently writing some Python code in a Jupyter notebook and I wonder if there is any possibility to track the execution of statements directly in Jupyter? I know there is this module called "trace": https://docs.python.org/3/library/trace.html#trace.Trace.results But it seems to me that with "trace" it is only possible to show the flow of execution in the console or to export it to a new file. However, I would like to display it directly in Jupyter Notebooks. Is this possible - with or without the mentioned module - and if yes how?
Thanks for your help.
For something along the lines of debugging code, you may be interested in the cell magic %%debug, discussed here to open a debugger in the notebook and use pdb commands. Or PixieDebugger if you need something fancier.
You may also be interested in the variable inspector extension for JupyterLab. There is (old) an animated example of using it here. You can easily try it out by clicking on launch binder badge there and starting a notebook. Then right-click in the open notebook and select Open Variable Inspector from the list. The animation will show you how to drag the tabs to arrange them side by side on your screen. Now as you run code, you'll see the variables updated.
I use version 1.38 of VSCode in combination with the python extension (ms-python.python) to be able to modify jupyter notebooks inside of VSCode. Is there any option to hide the output of specific cells (e.g. when plotting multiple plots in one cell)?
Bumped into the same problem today.
It seems to be that the shortcuts from jupyter notebook are integrated into the jupyter notebook in visual studio code.
If you press "o" on a cell, it will hide the cell output.
Put this as the first line of your cell.
%%capture
#Then the rest of your code in the cell...
The output from that cell won't be printed inside the notebook.
Seems like there's no option for that at the moment.
The official document here doesn't mention that.
https://code.visualstudio.com/docs/python/jupyter-support