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.
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¶
_token
instance-attribute
¶
label
property
¶
Get the widget label (alias for widget_id for BaseWidget protocol consistency).
Functions¶
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:
|
callback
|
Handler function receiving (data, event_type, label).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
InlineWidget
|
Self for method chaining. |
emit
¶
Send an event from Python to JavaScript.
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event name that JS listeners can subscribe to.
TYPE:
|
data
|
JSON-serializable payload to send to JavaScript.
TYPE:
|
send
¶
Alias for emit().
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
The event type (e.g., 'update_theme', 'custom_event').
TYPE:
|
data
|
The event data (will be JSON-serialized and sent to JS).
TYPE:
|
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:
|
alert_type
|
Alert type: 'info', 'success', 'warning', 'error', or 'confirm'.
TYPE:
|
title
|
Optional title for the toast.
TYPE:
|
duration
|
Auto-dismiss duration in ms. Defaults based on type.
TYPE:
|
callback_event
|
Event name to emit when confirm dialog is answered.
TYPE:
|
position
|
Toast position: 'top-right', 'top-left', 'bottom-right', 'bottom-left'.
TYPE:
|
update
¶
Update the widget's HTML content.
| PARAMETER | DESCRIPTION |
|---|---|
html
|
New HTML content to render. Should include necessary |