Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Colaboratory: Is there any way to expand the height of the result cell of running a code?

In Google Colaboratory notebook I have a loop that generates a lot of charts...my problem is that it does not display the full output nicely. Instead it shows it inside a cell with a scroll bar. I want to show the full result instead of scrolling up and down...but there doesn't seem to be any setting in Google Colaboratory that allows that. I was wondering if anyone knows if it's possible to change the cell height of the result? Thanks!

like image 948
Chadee Fouad Avatar asked Apr 06 '19 07:04

Chadee Fouad


People also ask

How do I insert a code cell above in Google Colab?

Now, the snippets are available in any colab notebook you use. Just click the <> icon on sidebar, search for your snippet name and click Insert. The code will be inserted into a new cell.

How do I view full output on Google Colab?

I just realized that you can go to the bottom left corner of the screen and click the button (if you hover over you see that it says "command palette"), then search "fullscreen" you find the button that says view output "fullscreen".

How do you break a cell in Google Colab?

As shown in Google Colab's "Keyboard shortcuts" window, the shortcut is "⌘/Ctrl+M -".


4 Answers

I managed to automate this for all cells in the entire Notebook.

Just create a cell with the following code and execute it, all the other cells in the Notebook will be automatically height-adjusted up to 5000px:

# Avoids scroll-in-the-scroll in the entire Notebook
from IPython.display import Javascript
def resize_colab_cell():
  display(Javascript('google.colab.output.setIframeHeight(0, true, {maxHeight: 5000})'))
get_ipython().events.register('pre_run_cell', resize_colab_cell)

(It's just a variation of the answers in this thread and a tip from here)

like image 133
caesarsol Avatar answered Nov 16 '22 03:11

caesarsol


There's an answer from a dev here. Note that the display(...) command must be included in every cell you wish to extend the max height of (unless maybe you write some extra javascript). Quote below.

An example in Python:

from IPython.display import Javascript
display(Javascript('''google.colab.output.setIframeHeight(0, true, {maxHeight: 5000})'''))

for i in range(200):
  print(i)
like image 29
Phoenix Meadowlark Avatar answered Nov 16 '22 02:11

Phoenix Meadowlark


This may help.

from IPython.display import Javascript
display(Javascript("google.colab.output.resizeIframeToContent()"))
like image 35
korakot Avatar answered Nov 16 '22 01:11

korakot


Try this:

from IPython.display import HTML
display(HTML('''
<style>
    pre {
        white-space: normal;
    }
</style>
'''))

print('x ' * 200)
like image 28
Jigyasa Gandhi Avatar answered Nov 16 '22 03:11

Jigyasa Gandhi