Skip to content

InlineWidget

The InlineWidget class powers browser-based rendering in PyWry. It starts a FastAPI server and serves widgets via IFrame or direct HTML, enabling Jupyter notebooks, browser tabs, and multi-user deploy mode.

from pywry.inline import InlineWidget

InlineWidget Class

pywry.inline.InlineWidget

InlineWidget(html: str, callbacks: dict[str, Callable[..., Any]] | None = None, width: str = '100%', height: int = 500, port: int | None = None, widget_id: str | None = None, headers: dict[str, str] | None = None, auth: Any | None = None, browser_only: bool = False, token: str | None = None)

Bases: GridStateMixin, PlotlyStateMixin, ToolbarStateMixin

Base inline widget that renders via FastAPI server and IFrame.

Implements BaseWidget protocol for unified API across rendering backends.

Attributes

_browser_only instance-attribute

_browser_only = browser_only

_widget_id instance-attribute

_widget_id = widget_id or hex

_token instance-attribute

_token = token if token is not None else _generate_widget_token(_widget_id)

_width instance-attribute

_width = width

_height instance-attribute

_height = height

_port instance-attribute

_port = port or port

_host instance-attribute

_host = host

_protocol instance-attribute

_protocol = 'https' if ssl_certfile else 'http'

_callbacks instance-attribute

_callbacks = callbacks or {}

_headers instance-attribute

_headers = headers or {}

_auth instance-attribute

_auth = auth

_output instance-attribute

_output = Output() if HAS_IPYTHON else None

widget_id property

widget_id: str

Get the widget ID.

label property

label: str

Get the widget label (alias for widget_id for BaseWidget protocol consistency).

output property

output: Output

Get the Output widget for callback output.

url property

url: str

Get the widget URL using configured prefix.

Functions

open_in_browser

open_in_browser() -> None

Open the chart in a new browser tab.

on

on(event_type: str, callback: Callable[[dict[str, Any], str, str], Any]) -> InlineWidget

Register a callback for events from JavaScript.

PARAMETER DESCRIPTION
event_type

Event name (e.g., 'plotly:click', 'toggle', 'grid:cell-click').

TYPE: str

callback

Handler function receiving (data, event_type, label).

TYPE: Callable[[dict[str, Any], str, str], Any]

RETURNS DESCRIPTION
InlineWidget

Self for method chaining.

emit

emit(event_type: str, data: dict[str, Any]) -> None

Send an event from Python to JavaScript.

PARAMETER DESCRIPTION
event_type

Event name that JS listeners can subscribe to.

TYPE: str

data

JSON-serializable payload to send to JavaScript.

TYPE: dict[str, Any]

send

send(event_type: str, data: Any) -> None

Alias for emit().

PARAMETER DESCRIPTION
event_type

The event type (e.g., 'update_theme', 'custom_event').

TYPE: str

data

The event data (will be JSON-serialized and sent to JS).

TYPE: Any

alert

alert(message: str, alert_type: str = 'info', title: str | None = None, duration: int | None = None, callback_event: str | None = None, position: str = 'top-right') -> None

Show a toast notification.

PARAMETER DESCRIPTION
message

The message to display.

TYPE: str

alert_type

Alert type: 'info', 'success', 'warning', 'error', or 'confirm'.

TYPE: str DEFAULT: 'info'

title

Optional title for the toast.

TYPE: str DEFAULT: None

duration

Auto-dismiss duration in ms. Defaults based on type.

TYPE: int DEFAULT: None

callback_event

Event name to emit when confirm dialog is answered.

TYPE: str DEFAULT: None

position

Toast position: 'top-right', 'top-left', 'bottom-right', 'bottom-left'.

TYPE: str DEFAULT: 'top-right'

update

update(html: str) -> None

Update the widget's HTML content.

PARAMETER DESCRIPTION
html

New HTML content to render. Should include necessary