Reputation: 951
I'm working through a tutorial in Google Colaboratory, and the author has handily hidden some of the solutions cells. When you click the hidden cell, it expands and becomes visible. How can I hide the cells?
An example is in this tutorial: Creating and Manipulating Tensors.
Upvotes: 62
Views: 110504
Reputation: 947
In the code area at Colab, add this line at the top
#@title don't show code till dblclick
your own code will be below:
print("hello world")
And After running the code area, you can see the title in Larger font at the top. Just double-click to hide/unhide
Upvotes: 1
Reputation: 1183
None of the other answers worked for me. You can collapse cells by adding this to the top of the cell "#@title" and then double clicking on the white space that appears to the right of it.
#@title Your Title Here
Upvotes: 96
Reputation: 2167
Since no one mention metadata setups to hide a cell code in form environment, I will share my findings.
This use case is if you want to make a notebook file in GitHub that has a banner to be opened in Colab, and you want the notebook to hide some cell.
To hide a code cell you need to:
Make the cell into form cell by adding #@title
on the very top of the cell.
add below metadata to the cell (you need to use plain text editor to do this):
"metadata": {
"cellView": "form",
"colab": {}
},
Upvotes: 1
Reputation: 1
just go on the top left corner (table of contents) then tap on +section. now on the left of the "new section" on your notebook there is a sign for the collapse of the cell and you are done.
Upvotes: 0
Reputation: 1
Just Make a new text cell and when writing the text include a # in the front it will make it a collapsable cell
without #
Use # infront of the title you want to enter and you are done
UPVOTE PLS
with #
Upvotes: -1
Reputation: 599
Here is the hot key for ya:
ctrl + "
After setting up the text part in Colab like what others have said, you can press control and quote key at the same time and collapse whichever cell/section you want.
Upvotes: -1
Reputation: 7745
To collapse/hide all cells without seeing them,
go to: menu → view → collapse sections, and click.
Upvotes: 4
Reputation: 71
To hide multiple cells.
Upvotes: 1
Reputation: 4267
The black triangle, that makes it possible to fold and unfold sections, appears when you create a section (which is equivalent to creating a title).
You can create a section by creating a text cell that starts with # <your section title>
.
This is how you create title in Markdown: # This is a title
## This is a smaller title
### This is even a smaller title
...
You can fold and unfold sections by clicking on the triangle next to their title.
This image illustrates how to create a section:
This image is the result of the previous image (note the magic triangle on the left):
Upvotes: 16
Reputation: 127
The text cell will become a collapse/expand tool and the cells below this text cell can be collapsed/expanded now
Upvotes: 3
Reputation: 31
It took me a while to figure out...but it is actually quite easy.
Manually collapse the section you would like manually, then go to "file/save". It will preserve the layout (including which section is collapsed) next time you open the notebook.
Hope a bit helpful!
Upvotes: 3
Reputation: 31
The most easiest way is to define "section" between your code cells. Then next to the title there an arrow using which you can hide all cells inside the section
Hide using sections:
Select multiple cells using SHIFT and your mouse click.
then do right click to get the Hide Cell option like this
Show hide cell option:
Upvotes: 3
Reputation: 81
I realise this question was posted some time ago but as a newbie to Google Colab myself I thought it would be helpful to share what I have found useful when 'collapsing' sections of code and generally organising code within my notebooks.
To add a collapsible section: proceed title with '#'
, all code below will fall within this title and can be collapsed. I.e. '#Import libraries'
will produce:
To add collapsible sub-sections (within the main header) simply add another '#'
, and so on. So, '##Check tf version'
would fall within '#Import libraries'
I hope this is helpful!
Upvotes: 8
Reputation: 11
If you are asking, how to replicate this:
What you can see in your screenshot is just what happens if you put text cells with a markup headings in between your code cells to create sections in your notebook.
In this case that would simply be a text cell containing just # Solution
above the two code cells.
You can hide and show the sections by clicking on the little triangle.
Upvotes: 1
Reputation: 1141
#@title
keyword (first line in your cell code)Upvotes: 22
Reputation: 1
If you need to hide code in your personal notebook, click at the gray vertical line (with 'run button') of the current cell and then check 'Hide code'
Upvotes: -1
Reputation: 40948
You can click at the “Triangle” in front of “Solution” heading. It will toggle between hide/show.
Upvotes: 2