Convert Figma logo to code with AI

jupyter-widgets logoipywidgets

Interactive Widgets for the Jupyter Notebook

3,129
950
3,129
752

Top Related Projects

11,556

Jupyter Interactive Notebook

34,470

Streamlit — A faster way to build and share data apps.

21,148

Data Apps & Dashboards for Python. No JavaScript Required.

19,206

Interactive Data Visualization in the browser, from Python

4,617

Panel: The powerful data exploration & web app framework for Python

5,383

Voilà turns Jupyter notebooks into standalone web applications

Quick Overview

ipywidgets is a Python library that provides interactive HTML widgets for Jupyter notebooks and the IPython kernel. It allows users to create interactive GUI elements such as sliders, buttons, and text inputs directly within Jupyter environments, enabling the creation of dynamic and interactive data visualizations and user interfaces.

Pros

  • Seamless integration with Jupyter notebooks and IPython
  • Wide variety of pre-built widgets for common use cases
  • Supports custom widget creation for advanced users
  • Enables interactive data exploration and visualization

Cons

  • Limited to Jupyter environments (not standalone)
  • Performance can be slow for complex widget interactions
  • Learning curve for creating custom widgets
  • Some widgets may have compatibility issues across different Jupyter versions

Code Examples

  1. Creating a simple slider widget:
import ipywidgets as widgets

slider = widgets.IntSlider(
    value=7,
    min=0,
    max=10,
    step=1,
    description='Test:',
    disabled=False,
    continuous_update=False,
    orientation='horizontal',
    readout=True,
    readout_format='d'
)
display(slider)
  1. Linking widgets together:
import ipywidgets as widgets
from IPython.display import display

a = widgets.FloatText()
b = widgets.FloatSlider()
widgets.jslink((a, 'value'), (b, 'value'))
display(a, b)
  1. Creating an interactive plot with widgets:
import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np

@widgets.interact(frequency=(0.1, 10, 0.1))
def plot_sine(frequency):
    t = np.linspace(0, 1, 1000)
    y = np.sin(2 * np.pi * frequency * t)
    plt.figure(figsize=(10, 5))
    plt.plot(t, y)
    plt.title(f'Sine Wave (Frequency: {frequency} Hz)')
    plt.xlabel('Time')
    plt.ylabel('Amplitude')
    plt.show()

Getting Started

To get started with ipywidgets, follow these steps:

  1. Install ipywidgets:
pip install ipywidgets
  1. If using Jupyter Notebook, enable the extension:
jupyter nbextension enable --py widgetsnbextension
  1. Import ipywidgets in your Jupyter notebook:
import ipywidgets as widgets
  1. Create and display a simple widget:
slider = widgets.IntSlider(value=5, min=0, max=10, description='Test:')
display(slider)

Now you can start creating interactive widgets in your Jupyter notebooks!

Competitor Comparisons

11,556

Jupyter Interactive Notebook

Pros of notebook

  • Provides a complete web-based interactive computing environment
  • Supports multiple programming languages (Python, R, Julia, etc.)
  • Integrates well with various data science and machine learning libraries

Cons of notebook

  • Can be resource-intensive, especially for large notebooks
  • Limited built-in interactive widgets compared to ipywidgets
  • May require additional setup for advanced features

Code Comparison

notebook:

from IPython.display import display
display(HTML('<button>Click me</button>'))

ipywidgets:

import ipywidgets as widgets
button = widgets.Button(description="Click me")
display(button)

The notebook example uses basic HTML for interactivity, while ipywidgets provides more sophisticated, Python-native interactive elements.

ipywidgets offers a wider range of pre-built widgets and allows for more complex interactions, making it better suited for creating rich, interactive dashboards within Jupyter environments. However, notebook provides a more comprehensive platform for general-purpose data analysis and exploration, supporting multiple languages and offering a familiar interface for many data scientists.

34,470

Streamlit — A faster way to build and share data apps.

Pros of Streamlit

  • Easier to create standalone web applications
  • More intuitive for those without web development experience
  • Faster development cycle with automatic reloading

Cons of Streamlit

  • Less flexibility in layout and design compared to ipywidgets
  • Limited to Python, while ipywidgets supports multiple kernels
  • May have performance issues with large datasets

Code Comparison

Streamlit example:

import streamlit as st

x = st.slider('Select a value')
st.write(f'You selected: {x}')

ipywidgets example:

from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets

@interact(x=widgets.IntSlider(min=-10, max=30, step=1, value=10))
def f(x):
    print(f'You selected: {x}')

Both libraries aim to create interactive data applications, but Streamlit focuses on creating standalone web apps, while ipywidgets is designed for use within Jupyter notebooks. Streamlit offers a more straightforward approach for those new to web development, while ipywidgets provides greater flexibility and integration with the Jupyter ecosystem.

21,148

Data Apps & Dashboards for Python. No JavaScript Required.

Pros of Dash

  • Full-stack web application framework, allowing for more complex and interactive dashboards
  • Supports real-time updates and callbacks for dynamic user interactions
  • Easier integration with external data sources and APIs

Cons of Dash

  • Steeper learning curve, especially for those unfamiliar with web development
  • Requires more setup and configuration compared to ipywidgets
  • Less seamless integration with Jupyter notebooks

Code Comparison

ipywidgets:

import ipywidgets as widgets
slider = widgets.IntSlider(value=50, min=0, max=100)
output = widgets.Output()
display(slider, output)

Dash:

import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Slider(min=0, max=100, value=50),
    html.Div(id='slider-output')
])

Both ipywidgets and Dash offer powerful tools for creating interactive visualizations and dashboards. ipywidgets excels in its simplicity and tight integration with Jupyter notebooks, making it ideal for quick prototyping and data exploration. Dash, on the other hand, provides a more comprehensive framework for building full-fledged web applications with advanced interactivity and scalability.

19,206

Interactive Data Visualization in the browser, from Python

Pros of Bokeh

  • More powerful and flexible for creating interactive visualizations
  • Supports standalone HTML output, making it easier to share and embed
  • Better suited for large datasets and real-time streaming data

Cons of Bokeh

  • Steeper learning curve compared to ipywidgets
  • Less seamless integration with Jupyter notebooks
  • Requires more code to create basic widgets and interactions

Code Comparison

ipywidgets:

import ipywidgets as widgets
slider = widgets.IntSlider(value=50, min=0, max=100)
display(slider)

Bokeh:

from bokeh.plotting import figure, show
from bokeh.models import Slider
slider = Slider(start=0, end=100, value=50, step=1, title="Value")
show(slider)

Both libraries offer interactive widgets for Jupyter notebooks and web applications. ipywidgets is more tightly integrated with Jupyter and easier to use for simple interactions, while Bokeh provides more advanced visualization capabilities and standalone output options. The choice between them depends on the specific requirements of your project and the level of complexity you need in your interactive visualizations.

4,617

Panel: The powerful data exploration & web app framework for Python

Pros of Panel

  • More flexible layout options and customization capabilities
  • Better support for creating dashboards and complex applications
  • Easier integration with various plotting libraries (Bokeh, Matplotlib, Plotly)

Cons of Panel

  • Steeper learning curve for beginners
  • Less native integration with Jupyter notebooks
  • Smaller community and ecosystem compared to ipywidgets

Code Comparison

ipywidgets:

import ipywidgets as widgets
slider = widgets.IntSlider(value=50, min=0, max=100)
output = widgets.Output()
display(slider, output)

Panel:

import panel as pn
slider = pn.widgets.IntSlider(value=50, start=0, end=100)
output = pn.pane.Markdown()
pn.Column(slider, output).servable()

Both libraries allow for interactive widgets, but Panel offers more flexibility in layout and design. ipywidgets is more tightly integrated with Jupyter notebooks, while Panel is better suited for creating standalone dashboards and applications. Panel's syntax is slightly more verbose but provides greater control over the final output.

5,383

Voilà turns Jupyter notebooks into standalone web applications

Pros of Voila

  • Easier deployment of Jupyter notebooks as standalone web applications
  • Supports custom templates for more flexible dashboard layouts
  • Better performance for large datasets due to server-side execution

Cons of Voila

  • Less interactive than ipywidgets for real-time data manipulation
  • Requires additional setup and configuration for deployment
  • Limited to Python-based widgets and visualizations

Code Comparison

Ipywidgets:

import ipywidgets as widgets
slider = widgets.IntSlider(description='Value')
display(slider)

Voila:

# In a Jupyter notebook
from ipywidgets import IntSlider
slider = IntSlider(description='Value')
slider
# Run: voila notebook.ipynb

Summary

Ipywidgets focuses on interactive widgets within Jupyter notebooks, offering real-time data manipulation and visualization. Voila, on the other hand, excels in turning notebooks into standalone web applications, making it easier to deploy and share dashboards. While Voila provides better performance for large datasets and custom layouts, it sacrifices some interactivity compared to ipywidgets. The choice between the two depends on the specific use case, with ipywidgets being more suitable for exploratory data analysis and Voila for creating shareable dashboards and applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ipywidgets: Interactive HTML Widgets

PurposeBadges
Latest (main: future 8.0)Test Status Documentation Status: latest Binder:main
StableVersion Conda Version Documentation Status Binder:7.x
CommunicationJoin the chat at https://gitter.im/ipython/ipywidgets Discourse

ipywidgets, also known as jupyter-widgets or simply widgets, are interactive HTML widgets for Jupyter notebooks and the IPython kernel.

Notebooks come alive when interactive widgets are used. Users gain control of their data and can visualize changes in the data.

Learning becomes an immersive, fun experience. Researchers can easily see how changing inputs to a model impact the results. We hope you will add ipywidgets to your notebooks, and we're here to help you get started.

The ipywidgets package is under the Jupyter-Widgets software subproject.

Core Interactive Widgets

The fundamental widgets provided by this library are called core interactive widgets. A demonstration notebook provides an overview of the core interactive widgets, including:

  • sliders
  • progress bars
  • text boxes
  • toggle buttons and checkboxes
  • display areas
  • and more

Jupyter Interactive Widgets as a Framework

Besides the widgets already provided with the library, the framework can be extended with the development of custom widget libraries. For detailed information, please refer to the ipywidgets documentation.

Cookiecutter template for custom widget development

A template project for building custom widgets is available as a cookiecutter. This cookiecutter project helps custom widget authors get started with the packaging and the distribution of their custom Jupyter interactive widgets. The cookiecutter produces a project for a Jupyter interactive widget library following the current best practices for using interactive widgets. An implementation for a placeholder "Hello World" widget is provided as an example.

Popular widget libraries such as bqplot, pythreejs and ipyleaflet follow exactly the same template and directory structure. They serve as more advanced examples of usage of the Jupyter widget infrastructure.

Popular custom widget examples

Examples of custom widget libraries built upon ipywidgets are

  • bqplot a 2d data visualization library enabling custom user interactions.
  • pythreejs a Jupyter - Three.js wrapper, bringing Three.js to the notebook.
  • ipyleaflet a leaflet widget for Jupyter.

Install

The stable version of ipywidgets can be installed with pip or conda.

With pip:

pip install ipywidgets

With conda:

conda install -c conda-forge ipywidgets

Developer install from source

Installing from source is more complicated and requires a developer install, see the detailed developer install instructions.

If you want to install ipywidgets from source, you will need the yarn package manager version 3 or later. To install the latest main version from the root directory of the source code, run dev-install.sh. To only build the Python package enter pip install -e ..

Usage

See the examples section of the documentation. The widgets are being used in a variety of ways; some uses can be seen in these notebooks: Demo notebook of interactive widgets

Change log

Change log

Version Compatibility with Front-End Clients

Refer to change log for more detail.

ipywidgetsJupyterLabClassic Notebooknbclassic
main-TBD
7.6.30.2.6
Legacy
6.x-
5.x4.2-
4.1.x4.1-
4.0.x4.0-

Contributing to ipywidgets

Developer information

License

We use a shared copyright model that enables all contributors to maintain the copyright on their contributions.

See the LICENSE file in this repository for details.

Project Jupyter resources

Weekly Team Meetings

Developer Meetings take place on zoom, on Tuesdays at 9:30AM Pacific Time (your time).

Minutes are taken at Hackmd.io.

NPM DownloadsLast 30 Days