Jupyter Notebook- run cell and select below not work - jupyter

I clicked the run and select below button or Shift + Enter twice, but it will skip the middle cell after finishing run the cell [16], and therefore, the middle cell was not exacuted.
enter image description here
My current environment about Jupyter notebook is as below:
enter image description here
I expect it will normally run the next cell after finishing the pervious one

Related

How to trans all cell in slides type in jupyter notebook(with nbconvert cmd)?

I want to Change all cell into slides type automatically by cmd, instead of doing it manually.

Jupyter Lab Max Number of Outputs Trimmed

How to change Jupyter Lab default behaviour trimming higher number of outputs.
The message in the middle of outputs says:
Output of this cell has been trimmed on the initial display.
Displaying the first 50 top and last bottom outputs.
Click on this message to get the complete output.
There is maxNumberOutputs parameter in Jupyter Lab source code, but I didn't found any method to change it.
You can change maxNumberOutputs in settings: click on Menu bar → Settings → Advanced Settings Editor → Notebook → set maxNumberOutputs in the User Preferences tab, like:
{
"maxNumberOutputs": 100
}
save, and reload.
Using jupyter lab path to find the "User settings" path, you can write from the notebook directly by executing this writefile magic from within a cell:
%%writefile <your-jupyter-lab-path>/user-settings/#jupyterlab/notebook-extension/tracker.jupyterlab-settings
{
"maxNumberOutputs":100
}
This path may be slightly different depending on your environment and Jupyterlab version, so probably best to manually change it using this answer and then finding the file that was modified. After that you can place this code before the %%writefile command to ensure that this works on your next Jupyter session without manually going to advanced settings in the menu bar:
!file="<your-jupyter-lab-path>/user-settings/#jupyterlab/notebook-extension/tracker.jupyterlab-settings" && mkdir -p "${file%/*}" && touch "$file"
Finally, to ensure that you have correctly changed the values,use this code to test your output:
from IPython.display import display
[display(i) for i in range(75)]
where 75 outputs should not be trimmed. If it is, then try refreshing the page to re-apply the settings.

Unable to view executed cell code in Spyder's IPython console [duplicate]

I updgraded from Spyder 3 to Spyder 4 and now when I execute a cell I need to wrap a print() around whatever variable is in the last line of the cell so that the contents are automatically printed / displayed in the console. What setting do I need to revert in order to get back to the prior set up.
in case this is not clear:
display = "1 2 3 4 5"
display
{Ctrl Enter}
would ouput:
1 2 3 4 5
to the console
now it does not display anything in the console
Thank you.
What setting do I need to revert in order to get back to the prior set up?
You need to go to the menu
Tools > Preferences > Editor > Run Code
and activate the option called
Copy full cell contents to the console when running code cells.

Shortcut for insert a cell below for Ipython in Pycharm?

I just started using Ipython in Pycharm.
What's the shortcut for insert a cell for Ipython in Pycharm?
To insert a cell between the 2nd and 3rd cell.
To insert a cell at the end of code
According to Pycharm documentation, way to add cell as follows.
But it doesn't work for me. Anyone find the same issue?
Since the new cell is added below the current one, click the cell with import statement - its frame becomes green. Then on the toolbar click add (or press Alt+Insert).
Not sure that is what you need, but you can insert cells above by Ctrl+Shift+Equals and below by Ctrl+Equals.
Update
All shortcuts for IPython Notebook are in Settings -> Keymap -> Plug-ins -> IPython Notebook
I've had the same concern and right now I remembered that you can just write #%% (for code cell) or #%% md (for markdown cell) anywhere you want and it will create a new cell

Jupyter Notebook: command for hide the output of a cell?

In my notebook, I have a cell returning temp calculation results. It's a bit long, so after it is run, I want to hide it and when needed, to show it.
To do it manually, I can double click the left side of the output, to hide it
After double click
But is there any way I can do this by code? For example,
the last line of the cell, use a command like %%hide output, and the output would be hidden after finished running.
Additionally, can I get this feature in output HTML?
Add ; by the end of the cell to hide the output of that cell.
In the newer versions(5.0.0 at the time I'm writing this), pressing o in the command mode hides the output of the cell in focus. The same happens if you triple click in front of the output.
o is
the first letter in the word "output" or
lower case of 15th letter in the alphabet
You can add %%capture to the beginning of the cell.
Jupyter provides a magic cell command called %%capture that allows you to capture all of to outputs from that cell.
You can use it like this:
%%capture test
print('test')
test.stdout => 'test\n'
https://ipython.readthedocs.io/en/stable/interactive/magics.html
In newer versions of Jupiter Notebook, select the desired cell, make sure you're in command mode and then on the menubar press Cell > Current Outputs. You have then three options:
Toggle (press O in the command mode to apply the same effect)
Toggle Scrolling (the default output)
Clear (to clear the output all together)
Image to Menubar Options
Additionally, you can apply the same effect to all the cells in your document if you chose All Output instead of Current Output.
Not exactly what you are after, but the effect might be good enough for your purposes:
Look into the %%capture magic (https://nbviewer.jupyter.org/github/ipython/ipython/blob/1.x/examples/notebooks/Cell%20Magics.ipynb). It lets you assign that cell output to a variable. By calling that variable later you could see the output.
Based on this, I just came up with this for myself a few minutes ago:
%%javascript
$('#maintoolbar-container').children('#toggleButton').remove()
var toggle_button = ("<button id='toggleButton' type='button'>Show Code</button>");
$('#maintoolbar-container').append(toggle_button);
var code_shown = false;
function code_toggle()
{
if (code_shown)
{
console.log("code shown")
$('div.input').hide('500');
$('#toggleButton').text('Show Code');
}
else
{
console.log("code not shown")
$('div.input').show('500');
$('#toggleButton').text('Hide Code');
}
code_shown = !code_shown;
}
$(document).ready(function()
{
code_shown=false;
$('div.input').hide();
});
$('#toggleButton').on('click', code_toggle);
It does have a glitch: each time you run that cell (which I put at the top), it adds a button. So, that is something that needs to be fixed. Would need to check in the maintoolbar-container to see if the button already exists, and then not add it.
EDIT
I added the necessary piece of code:
$('#maintoolbar-container').children('#toggleButton').remove()
You can use the notebook utils from https://github.com/google/etils:
!pip install etils[ecolab]
from etils import ecolab
with etils.collapse():
print('This content will be hidden by default')
It will capture the stdout/stderr output and display it a some collapsible section.
Internally, this is more or less equivalent to:
import contextlib
import html
import io
import IPython.display
#contextlib.contextmanager
def collapse(name: str = ''):
f = io.StringIO()
with contextlib.redirect_stderr(f):
with contextlib.redirect_stdout(f):
yield
name = html.escape(name)
content = f.getvalue()
content = html.escape(content)
content = f'<pre><code>{content}</code></pre>'
content = IPython.display.HTML(
f'<details><summary>{name}</summary>{content}</details>')
IPython.display.display(content)
The section is collapsed by default, but I uncollapsed it for the screenshot.
To prepend a cell from getting rendered in the output, in the notebook, by voilo or voila gridstack, just put in the first line of each cell to hide the output:
%%capture --no-display
reference in ipypthon documentation
For Windows,
in Jupyter Notebook, click the cell whose output you want to hide.
Click Esc + o for toggling the output
So I totally understand. When you have like 100 different plot and when you do the "Restart & Run All" those ugly plots all show up again
what you can do is ctrl+A and press o it will all of a sudden hide all your cells!!! For you to collapse automatically, you may need to use JupyterLab (another level after JupyterNotebook) but still, by doing ctrl+A then o you will be able to collapse all the results!!!
ctrl+A --> select ALL (make sure to click outside of coding box before you do it!)
o --> toggle collapse
If you don't mind a little hacking, then you may write a simple script for inverting the "collapsed" attribute of each cell from false to true
in the notebook .ipynb file (which is a simple JSON file).
This is however may fail in the future if a the .ipynb format changes.