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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
str
|
Event name (e.g., 'plotly:click', 'toggle', 'grid:cell-click'). |
required |
callback
|
Callable[[dict[str, Any], str, str], Any]
|
Handler function receiving (data, event_type, label). |
required |
Returns:
| Type | Description |
|---|---|
InlineWidget
|
Self for method chaining. |
emit
¶
Send an event from Python to JavaScript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
str
|
Event name that JS listeners can subscribe to. |
required |
data
|
dict[str, Any]
|
JSON-serializable payload to send to JavaScript. |
required |
send
¶
Alias for emit().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
str
|
The event type (e.g., 'update_theme', 'custom_event'). |
required |
data
|
Any
|
The event data (will be JSON-serialized and sent to JS). |
required |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display. |
required |
alert_type
|
str
|
Alert type: 'info', 'success', 'warning', 'error', or 'confirm'. |
'info'
|
title
|
str
|
Optional title for the toast. |
None
|
duration
|
int
|
Auto-dismiss duration in ms. Defaults based on type. |
None
|
callback_event
|
str
|
Event name to emit when confirm dialog is answered. |
None
|
position
|
str
|
Toast position: 'top-right', 'top-left', 'bottom-right', 'bottom-left'. |
'top-right'
|
update
¶
Update the widget's HTML content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html
|
str
|
New HTML content to render. Should include necessary |