'Can you hide code cell outputs in Google Colab?

Is there a way to hide a single code cell's output in Google Colab?

No one needs to see the sea of pip logs when we install things:

enter image description here

If you look at the screenshot you'll see I tried to apply one of the solutions from this similar Stack Overflow question: https://stackoverflow.com/a/48084050/1762493

I tried applying TagRemovePreprocessor.remove_single_output_tags as a #comment, a @@Magic, and a !command but those don't work with this line.

I checked Colab's "Welcome" and "Resource" notebooks but didn't notice anything there for deeper notebook settings: https://colab.research.google.com/notebooks/welcome.ipynb

Is this even possible?



Solution 1:[1]

I found this answer and applied it successfully: https://serverfault.com/a/41968/328943

Simply adding &> /dev/null to the tail of any command will silence its output outside of any errors that may arise.

Like so:

!pip install gwpy &> /dev/null

Solution 2:[2]

In this case you can just use

!pip install -q gwpy

In general, you can start the cell with %%capture

%%capture
# the rest of your code

Solution 3:[3]

This can be done by adding --quiet at the end. Thus for your case

!pip install gwpy --quiet

Solution 4:[4]

Just select the cell and press Ctrl+ M O. This will hide the output of the cell. This option is also available under the view tab.

Solution 5:[5]

Two ways:

  • Manage colab notebook by splitting it into sections, which can hide group of cells together with output. For instance, at the beginning I have "INIT" section, which loads pip's and necessary data from disk. One click, and initialized notebook is ready for work.
  • Stable code I hide with snippet at the beginning of each cell.

#@title 'What does it do'

If needed, output can be cleared too.

Other useful snippets can be found here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mikeumus
Solution 2 korakot
Solution 3 DaCard
Solution 4 Vikash Kumar
Solution 5 Nikolai Zaitsev