Interactive plots and applications in the browser from Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Interactive UI components for building data applications and dashboards. Bokeh provides a comprehensive widget system with 40+ widget types including buttons, inputs, tables, sliders, and specialized controls that enable rich user interactions with Python callbacks.
Interactive buttons and toggle controls for triggering actions and state changes.
class Button:
"""Standard push button widget."""
def __init__(self, label="Button", button_type="default", **kwargs):
"""
Parameters:
- label: str, button text
- button_type: str, button style ('default', 'primary', 'success', 'warning', 'danger', 'light')
"""
class Toggle:
"""Toggle button that maintains on/off state."""
def __init__(self, label="Toggle", active=False, button_type="default", **kwargs):
"""
Parameters:
- label: str, button text
- active: bool, initial toggle state
- button_type: str, button style
"""
class Dropdown:
"""Dropdown menu with selectable options."""
def __init__(self, label="Dropdown", button_type="default", menu=None, **kwargs):
"""
Parameters:
- label: str, dropdown label
- button_type: str, button style
- menu: list, menu items as (label, value) tuples or strings
"""Text and numeric input controls for data entry and parameter configuration.
class TextInput:
"""Single-line text input field."""
def __init__(self, value="", title=None, placeholder="", **kwargs):
"""
Parameters:
- value: str, initial text value
- title: str, input label
- placeholder: str, placeholder text
"""
class TextAreaInput:
"""Multi-line text input area."""
def __init__(self, value="", title=None, placeholder="", rows=2, **kwargs):
"""
Parameters:
- value: str, initial text content
- title: str, input label
- placeholder: str, placeholder text
- rows: int, number of visible text rows
"""
class NumericInput:
"""Numeric input with validation and formatting."""
def __init__(self, value=None, low=None, high=None, title=None, format=None, **kwargs):
"""
Parameters:
- value: float, initial numeric value
- low: float, minimum allowed value
- high: float, maximum allowed value
- title: str, input label
- format: str, number format pattern
"""
class PasswordInput:
"""Password input field with hidden text."""
def __init__(self, value="", title=None, placeholder="", **kwargs):
"""
Parameters:
- value: str, initial password value
- title: str, input label
- placeholder: str, placeholder text
"""
class FileInput:
"""File upload input widget."""
def __init__(self, accept="", multiple=False, **kwargs):
"""
Parameters:
- accept: str, accepted file types (MIME types or extensions)
- multiple: bool, allow multiple file selection
"""Widgets for selecting from predefined options and ranges.
class Select:
"""Dropdown selection widget."""
def __init__(self, value=None, title=None, options=None, **kwargs):
"""
Parameters:
- value: str, selected option value
- title: str, selection label
- options: list, available options as strings or (label, value) tuples
"""
class MultiSelect:
"""Multi-selection dropdown widget."""
def __init__(self, value=None, title=None, options=None, size=4, **kwargs):
"""
Parameters:
- value: list, selected option values
- title: str, selection label
- options: list, available options
- size: int, visible option count
"""
class AutocompleteInput:
"""Text input with autocomplete suggestions."""
def __init__(self, value="", title=None, completions=None, **kwargs):
"""
Parameters:
- value: str, initial input value
- title: str, input label
- completions: list, available completion strings
"""Grouped selection controls for multiple related options.
class CheckboxGroup:
"""Group of checkbox options."""
def __init__(self, labels=None, active=None, inline=False, **kwargs):
"""
Parameters:
- labels: list, checkbox labels
- active: list, indices of initially active checkboxes
- inline: bool, horizontal layout if True
"""
class RadioGroup:
"""Group of radio button options."""
def __init__(self, labels=None, active=None, inline=False, **kwargs):
"""
Parameters:
- labels: list, radio button labels
- active: int, index of initially active radio button
- inline: bool, horizontal layout if True
"""
class CheckboxButtonGroup:
"""Group of toggle buttons behaving like checkboxes."""
def __init__(self, labels=None, active=None, **kwargs):
"""
Parameters:
- labels: list, button labels
- active: list, indices of initially active buttons
"""
class RadioButtonGroup:
"""Group of toggle buttons behaving like radio buttons."""
def __init__(self, labels=None, active=None, **kwargs):
"""
Parameters:
- labels: list, button labels
- active: int, index of initially active button
"""Range and value selection through draggable slider controls.
class Slider:
"""Single-value slider widget."""
def __init__(self, start=0, end=1, value=0.5, step=0.1, title=None, **kwargs):
"""
Parameters:
- start: float, minimum slider value
- end: float, maximum slider value
- value: float, initial slider value
- step: float, increment between values
- title: str, slider label
"""
class RangeSlider:
"""Dual-handle slider for selecting value ranges."""
def __init__(self, start=0, end=1, value=(0.1, 0.9), step=0.1, title=None, **kwargs):
"""
Parameters:
- start: float, minimum range value
- end: float, maximum range value
- value: tuple, initial range as (low, high)
- step: float, increment between values
- title: str, slider label
"""
class DateSlider:
"""Slider for selecting dates."""
def __init__(self, start=None, end=None, value=None, step=1, title=None, **kwargs):
"""
Parameters:
- start: date, minimum date value
- end: date, maximum date value
- value: date, initial selected date
- step: int, step size in days
- title: str, slider label
"""
class DateRangeSlider:
"""Dual-handle slider for selecting date ranges."""
def __init__(self, start=None, end=None, value=None, step=1, title=None, **kwargs):
"""
Parameters:
- start: date, minimum date value
- end: date, maximum date value
- value: tuple, initial date range as (start_date, end_date)
- step: int, step size in days
- title: str, slider label
"""Specialized widgets for date and time selection with calendar interfaces.
class DatePicker:
"""Calendar-based date picker widget."""
def __init__(self, value=None, min_date=None, max_date=None, title=None, **kwargs):
"""
Parameters:
- value: date, initial selected date
- min_date: date, minimum selectable date
- max_date: date, maximum selectable date
- title: str, picker label
"""
class DateRangePicker:
"""Calendar-based date range picker widget."""
def __init__(self, value=None, min_date=None, max_date=None, title=None, **kwargs):
"""
Parameters:
- value: tuple, initial date range as (start_date, end_date)
- min_date: date, minimum selectable date
- max_date: date, maximum selectable date
- title: str, picker label
"""
class TimePicker:
"""Time selection widget with hour/minute controls."""
def __init__(self, value=None, min_time=None, max_time=None, title=None, **kwargs):
"""
Parameters:
- value: time, initial selected time
- min_time: time, minimum selectable time
- max_time: time, maximum selectable time
- title: str, picker label
"""
class DatetimePicker:
"""Combined date and time picker widget."""
def __init__(self, value=None, min_date=None, max_date=None, title=None, **kwargs):
"""
Parameters:
- value: datetime, initial selected datetime
- min_date: date, minimum selectable date
- max_date: date, maximum selectable date
- title: str, picker label
"""Interactive tabular data display with sorting, filtering, and editing capabilities.
class DataTable:
"""Interactive data table widget."""
def __init__(self, source=None, columns=None, width=600, height=400, **kwargs):
"""
Parameters:
- source: ColumnDataSource, table data source
- columns: list, TableColumn objects defining columns
- width: int, table width in pixels
- height: int, table height in pixels
"""
class TableColumn:
"""Column definition for data tables."""
def __init__(self, field=None, title=None, width=None, formatter=None, editor=None, **kwargs):
"""
Parameters:
- field: str, data field name
- title: str, column header text
- width: int, column width in pixels
- formatter: CellFormatter, cell display formatter
- editor: CellEditor, cell editor for inline editing
"""Widgets for displaying formatted text and content.
class Div:
"""HTML div element for rich text display."""
def __init__(self, text="", width=None, height=None, **kwargs):
"""
Parameters:
- text: str, HTML content to display
- width: int, div width in pixels
- height: int, div height in pixels
"""
class Paragraph:
"""Paragraph text display widget."""
def __init__(self, text="", width=None, height=None, **kwargs):
"""
Parameters:
- text: str, paragraph text content
- width: int, paragraph width in pixels
- height: int, paragraph height in pixels
"""
class PreText:
"""Preformatted text display widget."""
def __init__(self, text="", width=None, height=None, **kwargs):
"""
Parameters:
- text: str, preformatted text content
- width: int, text area width in pixels
- height: int, text area height in pixels
"""from bokeh.models.widgets import Button, TextInput, Select
from bokeh.io import show
from bokeh.layouts import column
# Create widgets
text_input = TextInput(title="Enter text:", placeholder="Type here...")
select_widget = Select(title="Choose option:", value="option1",
options=["option1", "option2", "option3"])
button = Button(label="Submit", button_type="primary")
# Arrange in layout
layout = column(text_input, select_widget, button)
show(layout)from bokeh.models.widgets import Slider, Select
from bokeh.plotting import figure, show
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource
# Create data source
source = ColumnDataSource(data=dict(x=[1, 2, 3, 4, 5], y=[2, 5, 3, 8, 7]))
# Create plot
plot = figure(width=400, height=400)
plot.circle('x', 'y', source=source, size=10)
# Create widgets
x_slider = Slider(title="X Multiplier", start=0.1, end=2.0, value=1.0, step=0.1)
y_select = Select(title="Y Transform", value="linear", options=["linear", "square", "sqrt"])
# Layout
layout = column(row(x_slider, y_select), plot)
show(layout)# Widget-specific types
MenuItemLike = Union[str, Tuple[str, str], None] # Menu item specification
OptionsLike = Union[List[str], List[Tuple[str, str]]] # Widget options
DateLike = Union[date, datetime, str] # Date specification
TimeLike = Union[time, datetime, str] # Time specification
# Table-related types
class CellFormatter:
"""Base formatter for table cells."""
class CellEditor:
"""Base editor for table cells."""
class NumberFormatter(CellFormatter):
"""Numeric cell formatter."""
def __init__(self, format="0,0", **kwargs): ...
class StringFormatter(CellFormatter):
"""String cell formatter."""
def __init__(self, font_style="normal", **kwargs): ...
class DateFormatter(CellFormatter):
"""Date cell formatter."""
def __init__(self, format="yy-mm-dd", **kwargs): ...