This tutorial will cover building user interfaces in Jupyter notebooks.
pynoon_plus_3.ipynbWe need to install jupyter_bokeh for panel
to work in Google Colab:
!pip install jupyter_bokehTo get started, let’s import the panel module that
provides widgets for building user interfaces
%pip install panel, but it’s
pre-installed in Colab.pn.extension() to finish loading
panel.import panel as pn
pn.extension()Now let’s make a text field:
text_field = pn.widgets.TextInput()We can display it:
text_fieldAnd we can get the current contents of the field:
text_field.valuetext_field.value.Now let’s make a button:
submit_button = pn.widgets.Button(name='Submit')
submit_buttonpn.bind() to assign a “callback” function
that should be called whenever the button is clicked.submit_button = pn.widgets.Button(name='Submit')
def on_submit(event):
    if not event:
        return
    return text_field.value
submit_output = pn.bind(on_submit, submit_button)
pn.Column(
    submit_button,
    submit_output,
)pn.bind() will display outputs
returned by the callback.
pn.Column.pn.bind() can also bind functions to any widget
updates, like text box changes.Each time you click the button, the current value of the text input is displayed.
text_field = pn.widgets.TextInput()
submit_button = pn.widgets.Button(name='Submit')
def on_submit(event):
    if not event:
        return
    return text_field.value
submit_output = pn.bind(on_submit, submit_button)
layout = pn.Column(
    text_field,
    submit_button,
    submit_output,
)
layoutpanel application with users is
to convert it to a shareable .html file.html is the language web pages are written in, so any
user will be able to open the file in their web browser.html files that can run Python code.pynoon_plus_3_app.ipynbimport panel as pn
pn.extension()
...interface...
layout.servable()layout ends with
.servable()
From your original notebook (important to avoid including the
!panel convert line in your app notebook):
Mount Drive!panel convert "drive/MyDrive/Colab Notebooks/pynoon_plus_3_app.ipynb" --to pyscript --out app_outputapp_output/pynoon_plus_3_app.htmlpynoon_plus_3_app.html in your web browser to use
your app!panel
documentation
Component Gallery -> Widgets in the
documentation sidebar)Component Gallery -> Panes in the
documentation sidebar)