Skip to content

Widgets & Rich Display

Jupyter can display much more than plain text:

from IPython.display import display, HTML, Image, Markdown, JSON, Audio, Video
# HTML
display(HTML("<h2 style='color:steelblue'>Hello</h2>"))
# Markdown
display(Markdown("## Heading\n- item 1\n- item 2"))
# Image from URL or file
display(Image(url="https://example.com/image.png", width=400))
display(Image(filename="chart.png"))
# JSON (collapsible tree)
display(JSON({"name": "Alice", "scores": [90, 85, 92]}))
# LaTeX math
from IPython.display import Math, Latex
display(Math(r'\frac{d}{dx}\left(x^n\right) = nx^{n-1}'))

Pandas DataFrames render as styled HTML tables automatically:

import pandas as pd
df = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Charlie'],
'Score': [90, 85, 92],
'Grade': ['A', 'B', 'A']
})
df # renders as table in last line of cell
# Styled DataFrame
df.style \
.highlight_max(subset=['Score'], color='lightgreen') \
.highlight_min(subset=['Score'], color='lightyellow') \
.format({'Score': '{:.1f}'})

Interactive UI controls that connect to Python:

Terminal window
pip install ipywidgets
import ipywidgets as widgets
from IPython.display import display
# Slider
slider = widgets.IntSlider(value=5, min=0, max=20, description='Value:')
display(slider)
print(slider.value) # read current value
# Interactive function
from ipywidgets import interact, interactive
@interact(x=(0, 10), y=(0, 10))
def add(x=5, y=5):
print(f"{x} + {y} = {x + y}")
# Dropdown
dropdown = widgets.Dropdown(
options=['Option A', 'Option B', 'Option C'],
value='Option A',
description='Choose:'
)
display(dropdown)
# Text input
text = widgets.Text(value='', placeholder='Type here', description='Name:')
display(text)
# Button with callback
button = widgets.Button(description='Click me', button_style='success')
output = widgets.Output()
def on_click(b):
with output:
print("Button clicked!")
button.on_click(on_click)
display(button, output)
import ipywidgets as widgets
# HBox / VBox
hbox = widgets.HBox([
widgets.Button(description='Left'),
widgets.Button(description='Right')
])
vbox = widgets.VBox([
widgets.Label('Settings'),
widgets.IntSlider(description='Alpha:'),
widgets.FloatSlider(description='Beta:')
])
display(hbox, vbox)
# Tab widget
tab = widgets.Tab()
tab.children = [
widgets.HTML("<p>Content of Tab 1</p>"),
widgets.HTML("<p>Content of Tab 2</p>")
]
tab.set_title(0, 'Tab 1')
tab.set_title(1, 'Tab 2')
display(tab)
from ipywidgets import IntProgress
from IPython.display import display
import time
progress = IntProgress(min=0, max=100, description='Processing:')
display(progress)
for i in range(101):
progress.value = i
time.sleep(0.02)
# tqdm integration (recommended)
from tqdm.notebook import tqdm
for i in tqdm(range(100)):
time.sleep(0.01)
# Matplotlib — static
import matplotlib.pyplot as plt
%matplotlib inline
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
plt.show()
# Plotly — interactive
import plotly.express as px
fig = px.scatter(df, x='x', y='y', color='category', hover_data=['name'])
fig.show()
# Altair — declarative
import altair as alt
chart = alt.Chart(df).mark_circle().encode(x='x', y='y', color='category')
chart
# Bokeh — interactive
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
output_notebook()
p = figure(title="My Plot")
p.circle([1, 2, 3], [4, 5, 6])
show(p)
# Hide a specific cell's code (show only output)
# Add tag 'hide-input' to cell metadata in JupyterLab:
# View → Cell Toolbar → Tags → add 'hide-input'
# Or use nbconvert with hide_input extension