I'm editing an .ipynb file in VS Code using the Jupyter Notebook extension. I can't seem to figure out how to collapse (or expand) cells.
Can someone explain to me how to do this (using hotkeys or not using hotkeys), or give ideas for what I might be doing wrong?
I tried each of the hotkeys shown below, under three sets of conditions: 1. with the blue vertical bar on the left-hand side of my cell input selected, 2. with the blue vertical bar on the left-hand side of my cell output selected, 3. with my cursor in my cell input.
And another way to collapse cells is coming to v1.64. See
Cell collapsing UI
Notebook cells have a blue bar on the left side to indicate that they
are focused. This bar is now interactive - you can click the top part
to collapse the cell input, and the bottom part to collapse the
output.
from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_64.md#cell-collapsing-ui
In my VSCode insiders build version 1.61.0, its working.
What's working ->
a) One shot expand/collapse all cells(code/output) in '.ipynb'(notebook)
b) Single cell code/output expand/collapse in '.ipynb'(notebook)
c) code folding in `.py` file with `#%%` (hierarchy style)
for .ipynb (your requirement)
There is keybinding available: jupyter.notebookeditor.expandallcells/collapseallcells
what it does?
Expands/collapses all cells in one shot
Find this setting->
Top menu File->Preferences->Keyboard Shortcuts
In search("Type to search in keybindings"...top side)
type "Notebook Expand" or "Notebook Collapse", check out:
Notebook: Expand/Collapse All Cells,
Notebook: Expand/Collapse Cell Input and
Notebook: Expand/Collapse Cell Output
Its possible to expand/collapse single/all cells with these shortcuts keys.
To make this answer complete (others have answered)->
1. double click gutter area (immediate space on left side of code cell) to Expand/Collapse cell (code/output)
2. right click on gutter area to get Expand/Collapse cell (code/output)
Detailed post for '.ipynb' and '.py' here
Currently, the use of this function is not supported in Jupyter of VS Code, you could refer to this link: Jupyter notebook cell code folding and output view expanding request.
Also, please try to use "Visual Studio Code Insiders", right-click in the cell of Jupyter, and select "Collapse Cell Input" or "Collapse Cell Output":
before:
after:
I'm using version 1.58.2 and this functionality is now available!
Simply right-click a code cell and select 'Collapse Cell Output'.
Alternatively, click a code cell (make sure you are in command mode) and use the keyboard shortcut ⌘K T (on Mac) or Ctrl-K T on Windows.
Related
I am plotting some figures using matplotlib inside a notebook in JupyterLab. The code which is plotting these figures is imported from a .py file present in the same directory as of the notebook.
Assuming that figures are of appropriate size, how can I display them entirely i.e. where scrolling is not needed or disabled to display the output and I can get one-shot overview of the output given it is not populating the display beyond the screen size?
The issue is resolved if I copy the code from .py file and run it in the notebook directly:
I have tried Toddneal's answer from Making a Jupyter notebook output cell fullscreen, but scroll bar still exists in the output cell. I also referred to How to avoid output into scrollable frames in jupyter notebook? and tried:
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;
}
as the first code cell in the notebook, but gives out the error: Javascript Error: Can't find variable: IPython.
The output cell is already expanded, so the issue is with the height of the output cell. There are bunch of cells beyond the output cells (could that be possibly affecting the height of output cell?). The extension autoscroll might not work because it is a Jupyter Notebook extension:
Due to major differences between the Jupyter Notebook and JupyterLab, the extensions in this repository will not work in JupyterLab.
As krassowki suggested in a comment, the scrolling is disabled by right-clicking on the output cell and choosing "Disable Scrolling for Outputs."
I am using VS Code 1.65.2 and it is very inconvenient for me to have the outputs of the cells of my Jupiter Notebook. I know that they can be removed one by one, but it is very cumbersome. Is there any configuration that hides these cells?
Click on it to hide the output.
I'm building a GUI using python with the tkinter library. I've created a table that imports data without issue and I'm able to select (highlight) individual cells and right click on them to bring up a menu for that cell. The problem is I first have to left-click on the cell to highlight/select it before right-clicking on it to bring up it's menu. If I left-click one cell and then right click a different cell, it brings up a menu for that highlighted cell, not that one that I right-clicked on.
My code is a bit too large to post but I'm hoping I can get some general ideas or sample code on how when I right-click on a cell, it selects it as well.
Thank you
Say I have a jupyter nootebook with 200 cells.
how to run from 5th cell to 100th cell, without running other part of the notebook?
Now I commend out 101th-200th and 1st-4th cell. I'm sure it is not the best practise.
One cannot just run cells 5 thru 100 easily with the Jupyter notebook but there are a few options. The first is just selecting each cell and running Merge Cell Above from the edit menu then just running the new cell. The second, and best way I've found to do this is:
First select the top cells to be ignored (or bottom if there are less on the bottom) and change the Cell Type to Raw NBConvert to prevent IPython from interpreting it.
Go to the cell after the one you want to run and select Run All Above (or below if less there).
Now you've only run those middle cells and can just go back and reset the cell type to code (instead of having to comment and then un-comment) and keep going.
* If you are using NBViewer you can hide the code or just set it to Markdown
Another option which requires less mouse movement and clicks than JGreenwell's answer, especially if you prefer accomplishing this with speedy keyboard work like I would:
Click in cell #1
Select all code (Ctrl+A)
Comment-out code (Ctrl+/)
Go to next cell (Shift+Enter) -- will execute cell, but is meaningless since all code is commented
Repeat steps 2-4 until cell #5
Select cell #200 and select Run All Above
Go back and un-comment cell 1-5 (Ctrl+A, Ctrl+/)
You can easily move between cells using the keyboard: Press Esc (command mode), Press J (up) or K (down) to select adjacent cell. Press Enter (to enter the code). Then press Ctrl+A then Ctrl+/ to un-comment. Repeat from Esc.
PyCharm displays little bars on the scroll bar for things like code warnings. This feature is called "inspection".
If you move the mouse cursor over a bar, it shows a preview of the code annotated with the inspection.
I find this really fiddly, and I'd actually like full inspection notices to be displayed all the time in the normal editor, just like it appears in the small preview.
Is there any way I can achieve this?
Using the default keymap, you can use F2 to jump to the next highlighted error and then Ctrl+F1 to show the tooltip.
According to this PyCharm's documentation there seems to be an Inspection Tool Window which displays inspection results on separate tabs..
You can access the tool window through menu Code | Inspect Code.
I just tried it and it showed a tab like this:
Press Alt+6
Or, click "Problems" on the bottom-left
Or click the error icons at the top-right of the text editor.
This gives a list of problems for the file open in the currently active tab. It automatically updates when you change tabs: