Using Panel in Google Colab

Is it possible to use Panel in Google Colaboratory. I can get it to work with
!pip install hvplot
!pip install panel

at the top of the notebook, and everything runs OK … but I don’t get any other output (other than stuff I can print() out).

Thanks for any help,

Chris

Yes, it is possible, but very awkward due to constraints imposed by colab: https://github.com/holoviz/holoviews/issues/3551

Thanks for the heads up. I didn’t know that about Colab.

Chris

Here’s what I do to use it in Colab

  • Add pn.extension() in any cell going to display
  • In some case, I need to update ipykernel !pip install ipykernel -U, then restart runtime.
1 Like

In Panel 0.10.2 (released 11/18/2020), you can now use pn.extension(comms='colab'), which automatically inserts the extension code into every cell. The notebook gets a bit bloated in file size, but that way you won’t have to put pn.extension() everywhere.

2 Likes

You may not need to insert into every cell. Only before cell that need to display.

Here’s what I did.

import panel as pn

def pn_repr(self, include=None, exclude=None):
    pn.extension()
    return pn.viewable.Viewable._repr_mimebundle_(self, include, exclude)
pn.layout.Panel._repr_mimebundle_ = pn_repr

It only call pn.extension() before a Panel is displayed with repe_mimebundle.

2 Likes

I also recently find out its easy to run servers in Google Colab. This is how you do for Streamlit. use panel serve for Panel instead.

run_in_colab