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

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

Related

Jupyter Notebook- run cell and select below not work

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

Is it possible to use %edit in an IPython Notebook to edit in-browser?

I have been using the magic %edit in Ipython to edit strings on the fly and was wondering whether this is also possible in an IPython Notebook without having to leave the browser (Possibly in a new cell)?
It turns out that %edit does not load variable content in a new cell in jupyter notebooks for now (https://github.com/jupyter/help/issues/147).
However, you can load variable s contents in a new cell by using %load s. you can then edit the content and store it in a new variable from within the same cell.

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.

jupyter notebooks slides: Skip as default

When using Jupyter for slides, is there a way to have Slide Type set to Skip for new cells, as a default?
My workaround for what you ask.
Create an empty "Skip" slide and type:
Esc
C
V
V
V
To copy and paste many empty "Skip" slides.
My workflow is as follows: I typically work on a notebook, do all the data explorations and only later I decide to convert it onto a slide-deck. This means setting the Slide Type to "Skip" (or "Sub-Slide") for many cells. It is unbearable to do it manually, so I go as follows:
in notebook, switch on the View >> Cell Toolbar >> Slideshow; this brings up a field with drop-down menu (with options "Slide", "Sub-Slide", etc.) at the upper right corner of every cell. Initially there is no value selected in any cell; you could now go cell by cell and select an option manually, or work as follows:
save and close the notebook
open the ipynb file in a text editor, e.g. Notepad++
find "metadata": { } and replace it by
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
(or 'slide_type_: "skip" for skipping) .
In my version of Notepad++ it actually means to use this replace string:
"metadata": {\n "slideshow": {\n "slide_type": "subslide"\n }\n },
while having the Search mode switched to "Extended":