panel.chat Package#
chat
Package#
Panel chat makes creating chat components easy#
Check out the widget gallery https://panel.holoviz.org/reference/index.html#chat for inspiration.
How to use Panel widgets in 3 simple steps#
Define your function
>>> async def repeat_contents(contents, user, instance):
>>> yield contents
Define your widgets and callback.
>>> chat_interface = ChatInterface(callback=repeat_contents)
Layout the chat interface in a template
>>> template = pn.template.FastListTemplate(
>>> title="Panel Chat",
>>> main=[chat_interface],
>>> )
>>> template.servable()
For more detail see the Reference Gallery guide. https://panel.holoviz.org/reference/chat/ChatInterface.html
- class panel.chat.ChatAreaInput(**params: Any)[source]#
Bases:
TextAreaInput
The ChatAreaInput allows entering any multiline string using a text input box, with the ability to press enter to submit the message.
Unlike TextAreaInput, the ChatAreaInput defaults to auto_grow=True and max_rows=10, and the value is not synced to the server until the enter key is pressed so bind on value_input if you need to access the existing value.
Lines are joined with the newline character n.
Reference: https://panel.holoviz.org/reference/chat/ChatAreaInput.html
- Example:
>>> ChatAreaInput(max_rows=10)
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, css_classes, design, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.widgets.base.Widget
: height, margin, disabledpanel.widgets.input._TextInputBase
: value, width, description, max_length, placeholder, value_inputauto_grow
= param.Boolean(allow_refs=False, default=True, label=’Auto grow’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12064c190>)Whether the text area should automatically grow vertically to accommodate the current text.
max_rows
= param.Integer(allow_refs=False, default=10, inclusive_bounds=(True, True), label=’Max rows’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11eab59d0>)When combined with auto_grow this determines the maximum number of rows the input area can grow.
rows
= param.Integer(allow_refs=False, default=1, inclusive_bounds=(True, True), label=’Rows’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11edcdc10>)Number of rows in the text input field.
resizable
= param.ObjectSelector(allow_refs=False, default=’height’, label=’Resizable’, names={}, nested_refs=False, objects=[‘both’, ‘width’, ‘height’, False], rx=<param.reactive.reactive_ops object at 0x11efa2ed0>)Whether the layout is interactively resizable, and if so in which dimensions: width, height, or both. Can only be set during initialization.
disabled_enter
= param.Boolean(allow_refs=False, default=False, label=’Disabled enter’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11b832b10>)If True, disables sending the message by pressing the enter_sends key.
enter_sends
= param.Boolean(allow_refs=False, default=True, label=’Enter sends’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11fae0a10>)If True, pressing the Enter key sends the message, if False it is sent by pressing the Ctrl+Enter.
- clone(**params) Viewable [source]#
Makes a copy of the object sharing the same parameters.
Arguments#
params: Keyword arguments override the parameters on the clone.
Returns#
Cloned Viewable object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- classmethod from_param(parameter: param.Parameter, onkeyup=False, **params) Viewable [source]#
Construct a widget from a Parameter and link the two bi-directionally.
Parameters#
- parameter: param.Parameter
A parameter to create the widget from.
- onkeyup: boolean
Whether to trigger events on every key press.
- params: dict
Keyword arguments to be passed to the widget constructor
Returns#
Widget instance linked to the supplied parameter
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- class panel.chat.ChatFeed(*objects, **params)[source]#
Bases:
ListPanel
A ChatFeed holds a list of ChatMessage objects and provides convenient APIs. to interact with them.
This includes methods to: - Send (append) messages to the chat log. - Stream tokens to the latest ChatMessage in the chat log. - Execute callbacks when a user sends a message. - Undo a number of sent ChatMessage objects. - Clear the chat log of all ChatMessage objects.
Reference: https://panel.holoviz.org/reference/chat/ChatFeed.html
- Example:
>>> async def say_welcome(contents, user, instance): >>> yield "Welcome!" >>> yield "Glad you're here!"
>>> chat_feed = ChatFeed(callback=say_welcome, header="Welcome Feed") >>> chat_feed.send("Hello World!", user="New User", avatar="😊")
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, css_classes, design, height, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.layout.base.ListPanel
: scrollmargin
= param.Margin(allow_None=True, allow_refs=True, default=5, label=’Margin’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120749cd0>)Allows to create additional space around the component. May be specified as a two-tuple of the form (vertical, horizontal) or a four-tuple (top, right, bottom, left).
objects
= param.Children(allow_refs=False, bounds=(0, None), class_=<class ‘panel.viewable.Viewable’>, default=[], item_type=<class ‘panel.viewable.Viewable’>, label=’Objects’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11f546f50>)The list of child objects that make up the layout.
auto_scroll_limit
= param.Integer(allow_refs=False, bounds=(0, None), default=200, inclusive_bounds=(True, True), label=’Auto scroll limit’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11ea7ddd0>)Max pixel distance from the latest object in the Column to activate automatic scrolling upon update. Setting to 0 disables auto-scrolling.
callback
= param.Callable(allow_None=True, allow_refs=False, label=’Callback’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120627a50>)Callback to execute when a user sends a message or when respond is called. The signature must include the previous message value contents, the previous user name, and the component instance.
callback_exception
= param.ObjectSelector(allow_refs=False, default=’summary’, label=’Callback exception’, names={}, nested_refs=False, objects=[‘raise’, ‘summary’, ‘verbose’, ‘ignore’], rx=<param.reactive.reactive_ops object at 0x11f98bc90>)How to handle exceptions raised by the callback. If “raise”, the exception will be raised. If “summary”, a summary will be sent to the chat feed. If “verbose”, the full traceback will be sent to the chat feed. If “ignore”, the exception will be ignored.
callback_user
= param.String(allow_refs=False, default=’Assistant’, label=’Callback user’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11f64b110>)The default user name to use for the message provided by the callback.
callback_avatar
= param.ClassSelector(allow_None=True, allow_refs=False, class_=(<class ‘str’>, <class ‘_io.BytesIO’>, <class ‘bytes’>, <class ‘panel.pane.image.ImageBase’>), label=’Callback avatar’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11d3f06d0>)The default avatar to use for the entry provided by the callback. Takes precedence over ChatMessage.default_avatars if set; else, if None, defaults to the avatar set in ChatMessage.default_avatars if matching key exists. Otherwise defaults to the first character of the callback_user.
card_params
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’Card params’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11f970f10>)Params to pass to Card, like header, header_background, header_color, etc.
collapsible
= param.Boolean(allow_refs=False, constant=True, default=False, label=’Collapsible’, nested_refs=False, readonly=True, rx=<param.reactive.reactive_ops object at 0x11e017490>)Whether the Card should be expandable and collapsible.
disabled
= param.Boolean(allow_refs=False, default=False, label=’Disabled’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11f64b110>)Whether the feed is disabled.
message_params
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’Message params’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120857e90>)Params to pass to each ChatMessage, like reaction_icons, timestamp_format, show_avatar, show_user, and show_timestamp. Params passed that are not ChatFeed params will be forwarded into message_params.
header
= param.Parameter(allow_None=True, allow_refs=False, label=’Header’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11fa29e10>)The header of the chat feed; commonly used for the title. Can be a string, pane, or widget.
help_text
= param.String(allow_refs=False, default=’’, label=’Help text’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11e017490>)If provided, initializes a chat message in the chat log using the provided help text as the message object and help as the user. This is useful for providing instructions, and will not be included in the serialize method by default.
load_buffer
= param.Integer(allow_refs=False, bounds=(0, None), default=50, inclusive_bounds=(True, True), label=’Load buffer’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11f98bc90>)The number of objects loaded on each side of the visible objects. When scrolled halfway into the buffer, the feed will automatically load additional objects while unloading objects on the opposite side.
placeholder_text
= param.String(allow_refs=False, default=’’, label=’Placeholder text’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120757490>)The text to display next to the placeholder icon.
placeholder_params
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={‘user’: ‘ ‘, ‘reaction_icons’: {}, ‘show_copy_icon’: False, ‘show_timestamp’: False}, label=’Placeholder params’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11fa54910>)Params to pass to the placeholder ChatMessage, like reaction_icons, timestamp_format, show_avatar, show_user, show_timestamp.
placeholder_threshold
= param.Number(allow_refs=False, bounds=(0, None), default=1, inclusive_bounds=(True, True), label=’Placeholder threshold’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207b4b90>)Min duration in seconds of buffering before displaying the placeholder. If 0, the placeholder will be disabled.
post_hook
= param.Callable(allow_None=True, allow_refs=False, label=’Post hook’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11fa29e10>)A hook to execute after a new message is completely added, i.e. the generator is exhausted. The stream method will trigger this callback on every call. The signature must include the message and instance arguments.
renderers
= param.HookList(allow_refs=False, bounds=(0, None), default=[], label=’Renderers’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11c692090>)A callable or list of callables that accept the value and return a Panel object to render the value. If a list is provided, will attempt to use the first renderer that does not raise an exception. If None, will attempt to infer the renderer from the value.
scroll_button_threshold
= param.Integer(allow_refs=False, bounds=(0, None), default=100, inclusive_bounds=(True, True), label=’Scroll button threshold’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11c561cd0>)Min pixel distance from the latest object in the Column to display the scroll button. Setting to 0 disables the scroll button.
show_activity_dot
= param.Boolean(allow_refs=False, default=True, label=’Show activity dot’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11f2ad890>)Whether to show an activity dot on the ChatMessage while streaming the callback response.
view_latest
= param.Boolean(allow_refs=False, default=True, label=’View latest’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120794dd0>)Whether to scroll to the latest object on init. If not enabled the view will be on the first object.
_placeholder
= param.ClassSelector(allow_None=True, allow_refs=False, class_=<class ‘panel.chat.message.ChatMessage’>, label=’ placeholder’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11c713410>)The placeholder wrapped in a ChatMessage object; primarily to prevent recursion error in _update_placeholder.
_callback_state
= param.ObjectSelector(allow_refs=False, label=’ callback state’, names={}, nested_refs=False, objects=[<CallbackState.IDLE: ‘idle’>, <CallbackState.RUNNING: ‘running’>, <CallbackState.GENERATING: ‘generating’>, <CallbackState.STOPPING: ‘stopping’>, <CallbackState.STOPPED: ‘stopped’>], rx=<param.reactive.reactive_ops object at 0x1207a8f90>)The current state of the callback.
_prompt_trigger
= param.Event(allow_refs=False, default=False, label=’ prompt trigger’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11e836f90>)Triggers the prompt input.
_callback_trigger
= param.Event(allow_refs=False, default=False, label=’ callback trigger’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207ab890>)Triggers the callback to respond.
_post_hook_trigger
= param.Event(allow_refs=False, default=False, label=’ post hook trigger’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11e526ed0>)Triggers the append callback.
_disabled_stack
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’ disabled stack’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11fc02850>)The previous disabled state of the feed.
- add_step(step: str | list[str] | ChatStep | None = None, append: bool = True, user: str | None = None, avatar: str | bytes | BytesIO | None = None, steps_layout: Column | Card | None = None, default_layout: Literal['column', 'card'] = 'card', layout_params: dict | None = None, **step_params) ChatStep [source]#
Adds a ChatStep component either by appending it to an existing ChatMessage or creating a new ChatMessage.
Arguments#
- stepstr | list(str) | ChatStep | None
The objects to stream to the step.
- appendbool
Whether to append to existing steps or create new steps.
- userstr | None
The user to stream as; overrides the message’s user if provided. Will default to the user parameter. Only applicable if steps is “new”.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message’s avatar if provided. Will default to the avatar parameter. Only applicable if steps is “new”.
- steps_layoutColumn | None
An existing layout of steps to stream to, if None is provided it will default to the last Column of steps or create a new one.
- default_layoutstr
The default layout to use if steps_layout is None. ‘column’ will create a new Column layout. ‘card’ will create a new Card layout.
- layout_paramsdict | None
Additional parameters to pass to the layout.
- step_paramsdict
Parameters to pass to the ChatStep.
- append(obj: Any) None [source]#
Appends an object to the layout.
Arguments#
obj (object): Panel component to add to the layout.
- clear() list[Any] [source]#
Clears the chat log and returns the messages that were cleared.
Returns#
The messages that were cleared.
- clone(*objects: Any, **params: Any) ListLike [source]#
Makes a copy of the layout sharing the same parameters.
Arguments#
objects: Objects to add to the cloned layout. params: Keyword arguments override the parameters on the clone.
Returns#
Cloned layout object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- extend(objects: Iterable[Any]) None [source]#
Extends the objects on this layout with a list.
Arguments#
objects (list): List of panel components to add to the layout.
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- index(object) int [source]#
Returns the integer index of the supplied object in the list of objects.
Arguments#
obj (object): Panel component to look up the index for.
Returns#
index (int): Integer index of the object in the layout.
- insert(index: int, obj: Any) None [source]#
Inserts an object in the layout at the specified index.
Arguments#
index (int): Index at which to insert the object. object (object): Panel components to insert in the layout.
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- pop(index: int) Viewable [source]#
Pops an item from the layout by index.
Arguments#
index (int): The index of the item to pop from the layout.
- prompt_user(component: Widget | ListPanel, callback: Callable | None = None, predicate: Callable | None = None, timeout: int = 120, timeout_message: str = 'Timed out', button_params: dict | None = None, timeout_button_params: dict | None = None, **send_kwargs) None [source]#
Prompts the user to interact with a form component.
Arguments#
- componentWidget | ListPanel
The component to prompt the user with.
- callbackCallable
The callback to execute once the user submits the form. The callback should accept two arguments: the component and the ChatFeed instance.
- predicateCallable | None
A predicate to evaluate the component’s state, e.g. widget has value. If provided, the button will be enabled when the predicate returns True. The predicate should accept the component as an argument.
- timeoutint
The duration in seconds to wait before timing out.
- timeout_messagestr
The message to display when the timeout is reached.
- button_paramsdict | None
Additional parameters to pass to the submit button.
- timeout_button_paramsdict | None
Additional parameters to pass to the timeout button.
- remove(obj: Viewable) None [source]#
Removes an object from the layout.
Arguments#
obj (object): The object to remove from the layout.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector=None)[source]#
Iterates over the ChatInterface and any potential children in the applying the selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- send(value: ChatMessage | dict | Any, user: str | None = None, avatar: str | bytes | BytesIO | None = None, respond: bool = True, **message_params) ChatMessage | None [source]#
Sends a value and creates a new message in the chat log.
If respond is True, additionally executes the callback, if provided.
Arguments#
- valueChatMessage | dict | Any
The message contents to send.
- userstr | None
The user to send as; overrides the message message’s user if provided.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message message’s avatar if provided.
- respondbool
Whether to execute the callback.
- message_paramsdict
Additional parameters to pass to the ChatMessage.
Returns#
The message that was created.
- serialize(exclude_users: list[str] | None = None, filter_by: Callable | None = None, format: Literal['transformers'] = 'transformers', custom_serializer: Callable | None = None, limit: int | None = None, **serialize_kwargs)[source]#
Exports the chat log.
Arguments#
- formatstr
The format to export the chat log as; currently only supports “transformers”.
- exclude_userslist(str) | None
A list of user (case insensitive names) to exclude from serialization. If not provided, defaults to [“help”]. This will be executed before filter_by.
- filter_bycallable
A function to filter the chat log by. The function must accept and return a list of ChatMessage objects.
- custom_serializercallable
A custom function to format the ChatMessage’s object. The function must accept one positional argument, the ChatMessage object, and return a string. If not provided, uses the serialize method on ChatMessage.
- limitint
The number of messages to serialize at most, starting from the last message.
- **serialize_kwargs
Additional keyword arguments to use for the specified format.
format=”transformers” role_names : dict(str, str | list(str)) | None
A dictionary mapping the role to the ChatMessage’s user name. Defaults to {“user”: [“user”], “assistant”: [self.callback_user]} if not set. The keys and values are case insensitive as the strings will all be lowercased. The values can be a string or a list of strings, e.g. {“user”: “user”, “assistant”: [“executor”, “langchain”]}.
- default_rolestr
The default role to use if the user name is not found in role_names. If this is set to None, raises a ValueError if the user name is not found.
Returns#
The chat log serialized in the specified format.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- stop() bool [source]#
Cancels the current callback task if possible.
Returns#
Whether the task was successfully stopped or done.
- stream(value: str | dict | ChatMessage, user: str | None = None, avatar: str | bytes | BytesIO | None = None, message: ChatMessage | None = None, replace: bool = False, **message_params) ChatMessage | None [source]#
Streams a token and updates the provided message, if provided. Otherwise creates a new message in the chat log, so be sure the returned message is passed back into the method, e.g. message = chat.stream(token, message=message).
This method is primarily for outputs that are not generators– notably LangChain. For most cases, use the send method instead.
Arguments#
- valuestr | dict | ChatMessage
The new token value to stream.
- userstr | None
The user to stream as; overrides the message’s user if provided.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message’s avatar if provided.
- messageChatMessage | None
The message to update.
- replacebool
Whether to replace the existing text when streaming a string or dict.
- message_paramsdict
Additional parameters to pass to the ChatMessage.
Returns#
The message that was updated.
- class panel.chat.ChatInterface(*objects, **params)[source]#
Bases:
ChatFeed
High level widget that contains the chat log and the chat input.
Reference: https://panel.holoviz.org/reference/chat/ChatInterface.html
- Example:
>>> async def repeat_contents(contents, user, instance): >>> yield contents
>>> chat_interface = ChatInterface( callback=repeat_contents, widgets=[TextInput(), FileInput()] )
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, css_classes, design, height, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.layout.base.ListPanel
: scrollpanel.chat.feed.ChatFeed
: margin, objects, auto_scroll_limit, callback, callback_exception, callback_user, callback_avatar, card_params, collapsible, disabled, message_params, header, help_text, load_buffer, placeholder_text, placeholder_params, placeholder_threshold, post_hook, renderers, scroll_button_threshold, show_activity_dot, view_latest, _placeholder, _callback_state, _prompt_trigger, _callback_trigger, _post_hook_trigger, _disabled_stackauto_send_types
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Auto send types’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11e282050>)The widget types to automatically send when the user presses enter or clicks away from the widget. If not provided, defaults to [TextInput].
avatar
= param.ClassSelector(allow_None=True, allow_refs=False, class_=(<class ‘str’>, <class ‘_io.BytesIO’>, <class ‘bytes’>, <class ‘panel.pane.image.ImageBase’>), label=’Avatar’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c0a50>)The avatar to use for the user. Can be a single character text, an emoji, or anything supported by pn.pane.Image. If not set, uses the first character of the name.
reset_on_send
= param.Boolean(allow_refs=False, default=True, label=’Reset on send’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120871650>)Whether to reset the widget’s value after sending a message; has no effect for TextInput.
show_send
= param.Boolean(allow_refs=False, default=True, label=’Show send’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c32d0>)Whether to show the send button.
show_stop
= param.Boolean(allow_refs=False, default=True, label=’Show stop’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120871650>)Whether to show the stop button temporarily replacing the send button during callback; has no effect if callback is not async.
show_rerun
= param.Boolean(allow_refs=False, default=True, label=’Show rerun’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c0a50>)Whether to show the rerun button.
show_undo
= param.Boolean(allow_refs=False, default=True, label=’Show undo’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120871650>)Whether to show the undo button.
show_clear
= param.Boolean(allow_refs=False, default=True, label=’Show clear’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c1ed0>)Whether to show the clear button.
show_button_name
= param.Boolean(allow_None=True, allow_refs=False, label=’Show button name’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120870a10>)Whether to show the button name.
user
= param.String(allow_refs=False, default=’User’, label=’User’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c1ed0>)Name of the ChatInterface user.
widgets
= param.ClassSelector(allow_None=True, allow_refs=False, class_=(<class ‘panel.widgets.base.WidgetBase’>, <class ‘list’>), label=’Widgets’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120870050>)Widgets to use for the input. If not provided, defaults to [TextInput].
button_properties
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’Button properties’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c1c10>)Allows addition of functionality or customization of buttons by supplying a mapping from the button name to a dictionary containing the icon, callback, post_callback, and/or js_on_click keys. If the button names correspond to default buttons (send, rerun, undo, clear), the default icon can be updated and if a callback key value pair is provided, the specified callback functionality runs before the existing one. For button names that don’t match existing ones, new buttons are created and must include a callback, post_callback, and/or js_on_click key. The provided callbacks should have a signature that accepts two positional arguments: instance (the ChatInterface instance) and event (the button click event). The js_on_click key should be a str or dict. If str, provide the JavaScript code; else if dict, it must have a code key, containing the JavaScript code to execute when the button is clicked, and optionally an args key, containing dictionary of arguments to pass to the JavaScript code.
_widgets
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’ widgets’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c1650>)The input widgets.
_input_container
= param.ClassSelector(allow_None=True, allow_refs=False, class_=<class ‘panel.layout.base.Row’>, label=’ input container’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c37d0>)The input message row that wraps the input layout (Tabs / Row) to easily swap between Tabs and Rows, depending on number of widgets.
_input_layout
= param.ClassSelector(allow_None=True, allow_refs=False, class_=(<class ‘panel.layout.base.Row’>, <class ‘panel.layout.tabs.Tabs’>), label=’ input layout’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c1650>)The input layout that contains the input widgets.
_button_data
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’ button data’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c37d0>)Metadata and data related to the buttons.
_buttons
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’ buttons’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209c25d0>)The rendered buttons.
- property active: int#
The currently active input widget tab index; -1 if there is only one widget available which is not in a tab.
Returns#
The active input widget tab index.
- property active_widget: WidgetBase#
The currently active widget.
Returns#
The active widget.
- add_step(step: str | list[str] | ChatStep | None = None, append: bool = True, user: str | None = None, avatar: str | bytes | BytesIO | None = None, steps_layout: Column | Card | None = None, default_layout: Literal['column', 'card'] = 'card', layout_params: dict | None = None, **step_params) ChatStep [source]#
Adds a ChatStep component either by appending it to an existing ChatMessage or creating a new ChatMessage.
Arguments#
- stepstr | list(str) | ChatStep | None
The objects to stream to the step.
- appendbool
Whether to append to existing steps or create new steps.
- userstr | None
The user to stream as; overrides the message’s user if provided. Will default to the user parameter. Only applicable if steps is “new”.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message’s avatar if provided. Will default to the avatar parameter. Only applicable if steps is “new”.
- steps_layoutColumn | None
An existing layout of steps to stream to, if None is provided it will default to the last Column of steps or create a new one.
- default_layoutstr
The default layout to use if steps_layout is None. ‘column’ will create a new Column layout. ‘card’ will create a new Card layout.
- layout_paramsdict | None
Additional parameters to pass to the layout.
- step_paramsdict
Parameters to pass to the ChatStep.
- append(obj: Any) None [source]#
Appends an object to the layout.
Arguments#
obj (object): Panel component to add to the layout.
- clear() list[Any] [source]#
Clears the chat log and returns the messages that were cleared.
Returns#
The messages that were cleared.
- clone(*objects: Any, **params: Any) ListLike [source]#
Makes a copy of the layout sharing the same parameters.
Arguments#
objects: Objects to add to the cloned layout. params: Keyword arguments override the parameters on the clone.
Returns#
Cloned layout object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- extend(objects: Iterable[Any]) None [source]#
Extends the objects on this layout with a list.
Arguments#
objects (list): List of panel components to add to the layout.
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- index(object) int [source]#
Returns the integer index of the supplied object in the list of objects.
Arguments#
obj (object): Panel component to look up the index for.
Returns#
index (int): Integer index of the object in the layout.
- insert(index: int, obj: Any) None [source]#
Inserts an object in the layout at the specified index.
Arguments#
index (int): Index at which to insert the object. object (object): Panel components to insert in the layout.
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- pop(index: int) Viewable [source]#
Pops an item from the layout by index.
Arguments#
index (int): The index of the item to pop from the layout.
- prompt_user(component: Widget | ListPanel, callback: Callable | None = None, predicate: Callable | None = None, timeout: int = 120, timeout_message: str = 'Timed out', button_params: dict | None = None, timeout_button_params: dict | None = None, **send_kwargs) None [source]#
Prompts the user to interact with a form component.
Arguments#
- componentWidget | ListPanel
The component to prompt the user with.
- callbackCallable
The callback to execute once the user submits the form. The callback should accept two arguments: the component and the ChatFeed instance.
- predicateCallable | None
A predicate to evaluate the component’s state, e.g. widget has value. If provided, the button will be enabled when the predicate returns True. The predicate should accept the component as an argument.
- timeoutint
The duration in seconds to wait before timing out.
- timeout_messagestr
The message to display when the timeout is reached.
- button_paramsdict | None
Additional parameters to pass to the submit button.
- timeout_button_paramsdict | None
Additional parameters to pass to the timeout button.
- remove(obj: Viewable) None [source]#
Removes an object from the layout.
Arguments#
obj (object): The object to remove from the layout.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector=None)[source]#
Iterates over the ChatInterface and any potential children in the applying the selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- send(value: ChatMessage | dict | Any, user: str | None = None, avatar: str | bytes | BytesIO | None = None, respond: bool = True, **message_params) ChatMessage | None [source]#
Sends a value and creates a new message in the chat log.
If respond is True, additionally executes the callback, if provided.
Arguments#
- valueChatMessage | dict | Any
The message contents to send.
- userstr | None
The user to send as; overrides the message message’s user if provided. Will default to the user parameter.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message message’s avatar if provided. Will default to the avatar parameter.
- respondbool
Whether to execute the callback.
- message_paramsdict
Additional parameters to pass to the ChatMessage.
Returns#
The message that was created.
- serialize(exclude_users: list[str] | None = None, filter_by: Callable | None = None, format: Literal['transformers'] = 'transformers', custom_serializer: Callable | None = None, limit: int | None = None, **serialize_kwargs)[source]#
Exports the chat log.
Arguments#
- formatstr
The format to export the chat log as; currently only supports “transformers”.
- exclude_userslist(str) | None
A list of user (case insensitive names) to exclude from serialization. If not provided, defaults to [“help”]. This will be executed before filter_by.
- filter_bycallable
A function to filter the chat log by. The function must accept and return a list of ChatMessage objects.
- custom_serializercallable
A custom function to format the ChatMessage’s object. The function must accept one positional argument, the ChatMessage object, and return a string. If not provided, uses the serialize method on ChatMessage.
- limitint
The number of messages to serialize at most, starting from the last message.
- **serialize_kwargs
Additional keyword arguments to use for the specified format.
format=”transformers” role_names : dict(str, str | list(str)) | None
A dictionary mapping the role to the ChatMessage’s user name. Defaults to {“user”: [“user”], “assistant”: [self.callback_user]} if not set. The keys and values are case insensitive as the strings will all be lowercased. The values can be a string or a list of strings, e.g. {“user”: “user”, “assistant”: [“executor”, “langchain”]}.
- default_rolestr
The default role to use if the user name is not found in role_names. If this is set to None, raises a ValueError if the user name is not found.
Returns#
The chat log serialized in the specified format.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- stop() bool [source]#
Cancels the current callback task if possible.
Returns#
Whether the task was successfully stopped or done.
- stream(value: str | dict | ChatMessage, user: str | None = None, avatar: str | bytes | BytesIO | None = None, message: ChatMessage | None = None, replace: bool = False, **message_params) ChatMessage | None [source]#
Streams a token and updates the provided message, if provided. Otherwise creates a new message in the chat log, so be sure the returned message is passed back into the method, e.g. message = chat.stream(token, message=message).
This method is primarily for outputs that are not generators– notably LangChain. For most cases, use the send method instead.
Arguments#
- valuestr | dict | ChatMessage
The new token value to stream.
- userstr | None
The user to stream as; overrides the message’s user if provided. Will default to the user parameter.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message’s avatar if provided. Will default to the avatar parameter.
- messageChatMessage | None
The message to update.
- replacebool
Whether to replace the existing text when streaming a string or dict.
- message_paramsdict
Additional parameters to pass to the ChatMessage.
Returns#
The message that was updated.
- class panel.chat.ChatMessage(object=None, **params)[source]#
Bases:
Pane
Renders another component as a chat message with an associated user and avatar with support for various content types.
This widget provides a structured view of chat messages, including features like:
Displaying user avatars, which can be text, emoji, or images.
Showing the user’s name.
Displaying the message timestamp in a customizable format.
Associating reactions with messages and mapping them to icons.
Rendering various content types including text, images, audio, video, and more.
Reference: https://panel.holoviz.org/reference/chat/ChatMessage.html
- Example:
>>> ChatMessage(object="Hello world!", user="New User", avatar="😊")
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, design, height, min_width, min_height, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.pane.base.PaneBase
: margin, default_layoutcss_classes
= param.List(allow_refs=True, bounds=(0, None), default=[‘chat-message’], label=’Css classes’, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x1208096d0>)The CSS classes to apply to the widget.
max_width
= param.Integer(allow_None=True, allow_refs=True, bounds=(0, None), default=1200, inclusive_bounds=(True, True), label=’Max width’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209bb190>)Minimal width of the component (in pixels) if width is adjustable.
object
= param.Parameter(allow_None=True, allow_refs=False, label=’Object’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120987110>)The message contents. Can be any Python object that panel can display.
avatar
= param.ClassSelector(allow_refs=False, class_=(<class ‘str’>, <class ‘_io.BytesIO’>, <class ‘bytes’>, <class ‘panel.pane.image.ImageBase’>), default=’’, label=’Avatar’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209b85d0>)The avatar to use for the user. Can be a single character text, an emoji, or anything supported by pn.pane.Image. If not set, checks if the user is available in the default_avatars mapping; else uses the first character of the name.
avatar_lookup
= param.Callable(allow_None=True, allow_refs=False, label=’Avatar lookup’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1208096d0>)A function that can lookup an avatar from a user name. The function signature should be (user: str) -> Avatar. If this is set, default_avatars is disregarded.
default_avatars
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={‘client’: ‘🧑’, ‘customer’: ‘🧑’, ‘employee’: ‘🧑’, ‘human’: ‘🧑’, ‘person’: ‘🧑’, ‘user’: ‘🧑’, ‘agent’: ‘🤖’, ‘ai’: ‘🤖’, ‘assistant’: ‘🤖’, ‘bot’: ‘🤖’, ‘chatbot’: ‘🤖’, ‘machine’: ‘🤖’, ‘robot’: ‘🤖’, ‘system’: ‘⚙️’, ‘exception’: ‘❌’, ‘error’: ‘❌’, ‘help’: ‘❓’, ‘input’: ‘❗’, ‘adult’: ‘🧑’, ‘baby’: ‘👶’, ‘boy’: ‘👦’, ‘child’: ‘🧒’, ‘girl’: ‘👧’, ‘man’: ‘👨’, ‘woman’: ‘👩’, ‘chatgpt’: ‘{dist_path}assets/logo/gpt-3.svg’, ‘gpt3’: ‘{dist_path}assets/logo/gpt-3.svg’, ‘gpt4’: ‘{dist_path}assets/logo/gpt-4.svg’, ‘dalle’: ‘{dist_path}assets/logo/gpt-4.svg’, ‘openai’: ‘{dist_path}assets/logo/gpt-4.svg’, ‘huggingface’: ‘🤗’, ‘calculator’: ‘🧮’, ‘langchain’: ‘🦜’, ‘retriever’: ‘📄’, ‘tool’: ‘🛠️’, ‘translator’: ‘🌐’, ‘wolfram’: ‘{dist_path}assets/logo/wolfram.svg’, ‘wolfram alpha’: ‘{dist_path}assets/logo/wolfram.svg’, ‘llama’: ‘🦙’, ‘llama2’: ‘🐪’, ‘plot’: ‘📊’, ‘lumen’: ‘{dist_path}assets/logo/lumen.svg’, ‘holoviews’: ‘{dist_path}assets/logo/holoviews.svg’, ‘hvplot’: ‘{dist_path}assets/logo/hvplot.svg’, ‘panel’: ‘{dist_path}images/icon-vector.svg’}, label=’Default avatars’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209b96d0>)A default mapping of user names to their corresponding avatars to use when the user is specified but the avatar is. You can modify, but not replace the dictionary.
footer_objects
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Footer objects’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209b9810>)A list of objects to display in the column of the footer of the message.
header_objects
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Header objects’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209bb950>)A list of objects to display in the row of the header of the message.
reactions
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Reactions’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209b8890>)Reactions to associate with the message.
reaction_icons
= param.ClassSelector(allow_None=True, allow_refs=False, class_=<class ‘panel.chat.icon.ChatReactionIcons’>, label=’Reaction icons’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209b85d0>)A mapping of reactions to their reaction icons; if not provided defaults to {“favorite”: “heart”}.
timestamp
= param.Date(allow_None=True, allow_refs=False, inclusive_bounds=(True, True), label=’Timestamp’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209bbb90>)Timestamp of the message. Defaults to the creation time.
timestamp_format
= param.String(allow_refs=False, default=’%H:%M’, label=’Timestamp format’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209b8990>)The timestamp format.
timestamp_tz
= param.String(allow_None=True, allow_refs=False, label=’Timestamp tz’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12093ca90>)The timezone to used for the creation timestamp; only applicable if timestamp is not set. If None, tries to use pn.state.browser_info.timezone, else, the default tz of datetime.datetime.now(); see zoneinfo.available_timezones() for a list of valid timezones.
show_avatar
= param.Boolean(allow_refs=False, default=True, label=’Show avatar’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209b9350>)Whether to display the avatar of the user.
show_user
= param.Boolean(allow_refs=False, default=True, label=’Show user’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1208096d0>)Whether to display the name of the user.
show_timestamp
= param.Boolean(allow_refs=False, default=True, label=’Show timestamp’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209bb810>)Whether to display the timestamp of the message.
show_reaction_icons
= param.Boolean(allow_refs=False, default=True, label=’Show reaction icons’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12093e410>)Whether to display the reaction icons.
show_copy_icon
= param.Boolean(allow_refs=False, default=True, label=’Show copy icon’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209bb2d0>)Whether to display the copy icon.
show_activity_dot
= param.Boolean(allow_refs=False, default=False, label=’Show activity dot’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12093f550>)Whether to show the activity dot.
renderers
= param.HookList(allow_refs=False, bounds=(0, None), default=[], label=’Renderers’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1209ba850>)A callable or list of callables that accept the object and return a Panel object to render the object. If a list is provided, will attempt to use the first renderer that does not raise an exception. If None, will attempt to infer the renderer from the object.
user
= param.Parameter(allow_refs=False, default=’User’, label=’User’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12093f550>)Name of the user who sent the message.
- classmethod applies(obj: Any) float | bool | None [source]#
Returns boolean or float indicating whether the Pane can render the object.
If the priority of the pane is set to None, this method may also be used to define a float priority depending on the object being rendered.
- clone(object: Any | None = None, **params) T [source]#
Makes a copy of the Pane sharing the same parameters.
Arguments#
object: Optional new object to render params: Keyword arguments override the parameters on the clone.
Returns#
Cloned Pane object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- classmethod get_pane_type(obj: Any, **kwargs) type[PaneBase] [source]#
Returns the applicable Pane type given an object by resolving the precedence of all types whose applies method declares that the object is supported.
Arguments#
obj (object): The object type to return a Pane type for
Returns#
The applicable Pane type with the highest precedence.
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.document.Document
Optional Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: bool (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- serialize(prefix_with_viewable_label: bool = True, prefix_with_container_label: bool = True) str [source]#
Format the object to a string.
Arguments#
- prefix_with_viewable_labelbool
Whether to include the name of the Viewable, or type of the viewable if no name is specified.
- prefix_with_container_labelbool
Whether to include the name of the container, or type of the container if no name is specified.
Returns#
- str
The serialized string.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- stream(token: str, replace: bool = False)[source]#
Updates the message with the new token traversing the object to allow updating nested objects. When traversing a nested Panel the last object that supports rendering strings is updated, e.g. in a layout of Column(Markdown(…), Image(…)) the Markdown pane is updated.
Arguments#
- token: str
The token to stream to the text pane.
- replace: bool (default=False)
Whether to replace the existing text.
- update(value: dict | ChatMessage | Any, user: str | None = None, avatar: str | bytes | BytesIO | None = None)[source]#
Updates the message with a new value, user and avatar.
Arguments#
- valueChatMessage | dict | Any
The message contents to send.
- userstr | None
The user to send as; overrides the message message’s user if provided.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message message’s avatar if provided.
- class panel.chat.ChatReactionIcons(*, active_icons, default_layout, options, disabled, loading, align, aspect_ratio, css_classes, design, height, height_policy, margin, max_height, max_width, min_height, min_width, sizing_mode, styles, stylesheets, tags, visible, width, width_policy, value, name)[source]#
Bases:
CompositeWidget
A widget to display reaction icons that can be clicked on.
Parameters#
- valueList
The selected reactions.
- optionsDict
A key-value pair of reaction values and their corresponding tabler icon names found on https://tabler-icons.io.
- active_iconsDict
The mapping of reactions to their corresponding active icon names; if not set, the active icon name will default to its “filled” version.
Reference: https://panel.holoviz.org/reference/chat/ChatReactionIcons.html
- Example:
>>> ChatReactionIcons(value=["like"], options={"like": "thumb-up", "dislike": "thumb-down"})
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, design, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.widgets.base.Widget
: height, width, disabledvalue
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Value’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1208299d0>)The active reactions.
css_classes
= param.List(allow_refs=True, bounds=(0, None), default=[‘reaction-icons’], label=’Css classes’, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x12093f4d0>)The CSS classes of the widget.
margin
= param.Margin(allow_None=True, allow_refs=True, default=0, label=’Margin’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120828550>)Allows to create additional space around the component. May be specified as a two-tuple of the form (vertical, horizontal) or a four-tuple (top, right, bottom, left).
active_icons
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’Active icons’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12082a950>)The mapping of reactions to their corresponding active icon names. If not set, the active icon name will default to its “filled” version.
options
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={‘favorite’: ‘heart’}, label=’Options’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120828550>)A key-value pair of reaction values and their corresponding tabler icon names found on https://tabler-icons.io.
default_layout
= param.ClassSelector(allow_refs=False, class_=<class ‘panel.layout.base.Panel’>, default=<class ‘panel.layout.base.Column’>, label=’Default layout’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12082bb10>)- clone(**params) Viewable [source]#
Makes a copy of the object sharing the same parameters.
Arguments#
params: Keyword arguments override the parameters on the clone.
Returns#
Cloned Viewable object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- classmethod from_param(parameter: param.Parameter, **params) T [source]#
Construct a widget from a Parameter and link the two bi-directionally.
Parameters#
- parameter: param.Parameter
A parameter to create the widget from.
Returns#
Widget instance linked to the supplied parameter
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- class panel.chat.ChatStep(*objects, **params)[source]#
Bases:
Card
A component that makes it easy to provide status updates and the ability to stream updates to both the output(s) and the title.
Reference: https://panel.holoviz.org/reference/chat/ChatStep.html
- Example:
>>> ChatStep("Hello world!", title="Running calculation...', status="running")
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, design, height, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.layout.base.ListLike
: objectspanel.layout.base.ListPanel
: scrollpanel.layout.base.Column
: auto_scroll_limit, scroll_button_threshold, scroll_position, view_latestpanel.layout.card.Card
: css_classes, active_header_background, button_css_classes, collapsible, header_background, header_color, header_css_classes, hide_header, title_css_classesmargin
= param.Parameter(allow_refs=True, default=(5, 5, 5, 10), label=’Margin’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207de350>)Allows to create additional space around the component. May be specified as a two-tuple of the form (vertical, horizontal) or a four-tuple (top, right, bottom, left).
collapsed
= param.Boolean(allow_refs=False, default=False, label=’Collapsed’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207dcf90>)Whether the contents of the Card are collapsed.
header
= param.Parameter(allow_None=True, allow_refs=False, constant=True, label=’Header’, nested_refs=False, readonly=True, rx=<param.reactive.reactive_ops object at 0x1207ded50>)A Panel component to display in the header bar of the Card. Will override the given title if defined.
title
= param.String(allow_refs=False, constant=True, default=’’, label=’Title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207dcf90>)The title of the chat step. Will redirect to default_title on init. After, it cannot be set directly; instead use the *_title params.
collapsed_on_success
= param.Boolean(allow_refs=False, default=True, label=’Collapsed on success’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207df5d0>)Whether to collapse the card on completion.
context_exception
= param.ObjectSelector(allow_refs=False, default=’raise’, label=’Context exception’, names={}, nested_refs=False, objects=[‘raise’, ‘summary’, ‘verbose’, ‘ignore’], rx=<param.reactive.reactive_ops object at 0x12082f950>)How to handle exceptions raised upon exiting the context manager. If “raise”, the exception will be raised. If “summary”, a summary will be sent to the chat step. If “verbose”, the full traceback will be sent to the chat step. If “ignore”, the exception will be ignored.
success_title
= param.String(allow_None=True, allow_refs=False, label=’Success title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207defd0>)Title to display when status is success.
default_badges
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={‘pending’: BooleanStatus(color=’primary’, margin=0), ‘running’: BooleanStatus(color=’warning’, margin=0, value=True), ‘success’: BooleanStatus(color=’success’, margin=0, value=True), ‘failed’: BooleanStatus(color=’danger’, margin=0, value=True)}, label=’Default badges’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207dd210>)Mapping from status to default status badge; keys must be one of ‘pending’, ‘running’, ‘success’, ‘failed’.
default_title
= param.String(allow_refs=False, default=’’, label=’Default title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11d47a650>)The default title to display if the other title params are unset.
failed_title
= param.String(allow_None=True, allow_refs=False, label=’Failed title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207df110>)Title to display when status is failed.
pending_title
= param.String(allow_None=True, allow_refs=False, label=’Pending title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11dc76650>)Title to display when status is pending.
running_title
= param.String(allow_None=True, allow_refs=False, label=’Running title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207ddc90>)Title to display when status is running.
status
= param.Selector(allow_refs=False, default=’pending’, label=’Status’, names={}, nested_refs=False, objects=[‘pending’, ‘running’, ‘success’, ‘failed’], rx=<param.reactive.reactive_ops object at 0x11dc76350>)- append(obj: Any) None [source]#
Appends an object to the layout.
Arguments#
obj (object): Panel component to add to the layout.
- clear() list[Viewable] [source]#
Clears the objects on this layout.
Returns#
objects (list[Viewable]): List of cleared objects.
- clone(*objects: Any, **params: Any) ListLike [source]#
Makes a copy of the layout sharing the same parameters.
Arguments#
objects: Objects to add to the cloned layout. params: Keyword arguments override the parameters on the clone.
Returns#
Cloned layout object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- extend(objects: Iterable[Any]) None [source]#
Extends the objects on this layout with a list.
Arguments#
objects (list): List of panel components to add to the layout.
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- index(object) int [source]#
Returns the integer index of the supplied object in the list of objects.
Arguments#
obj (object): Panel component to look up the index for.
Returns#
index (int): Integer index of the object in the layout.
- insert(index: int, obj: Any) None [source]#
Inserts an object in the layout at the specified index.
Arguments#
index (int): Index at which to insert the object. object (object): Panel components to insert in the layout.
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- pop(index: int) Viewable [source]#
Pops an item from the layout by index.
Arguments#
index (int): The index of the item to pop from the layout.
- remove(obj: Viewable) None [source]#
Removes an object from the layout.
Arguments#
obj (object): The object to remove from the layout.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- serialize(prefix_with_viewable_label: bool = True, prefix_with_container_label: bool = True) str [source]#
Format the object to a string.
Arguments#
- prefix_with_viewable_labelbool
Whether to include the name of the Viewable, or type of the viewable if no name is specified.
- prefix_with_container_labelbool
Whether to include the name of the container, or type of the container if no name is specified.
Returns#
- str
The serialized string.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- stream(token: str | None, replace: bool = False)[source]#
Stream a token to the last available string-like object.
Arguments#
- tokenstr
The token to stream.
- replacebool
Whether to replace the existing text.
Returns#
- Viewable
The updated message pane.
- stream_title(token: str, status: Literal['pending', 'running', 'success', 'failed', 'default'] = 'running', replace: bool = False)[source]#
Stream a token to the title header.
Arguments:#
- tokenstr
The token to stream.
- statusstr
The status title to stream to, one of ‘pending’, ‘running’, ‘success’, ‘failed’, or “default”.
- replacebool
Whether to replace the existing text.
feed
Module#
The feed module provides a high-level API for interacting with a list of ChatMessage objects through the backend methods.
- class panel.chat.feed.CallbackState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
- class panel.chat.feed.ChatFeed(*objects, **params)[source]#
Bases:
ListPanel
A ChatFeed holds a list of ChatMessage objects and provides convenient APIs. to interact with them.
This includes methods to: - Send (append) messages to the chat log. - Stream tokens to the latest ChatMessage in the chat log. - Execute callbacks when a user sends a message. - Undo a number of sent ChatMessage objects. - Clear the chat log of all ChatMessage objects.
Reference: https://panel.holoviz.org/reference/chat/ChatFeed.html
- Example:
>>> async def say_welcome(contents, user, instance): >>> yield "Welcome!" >>> yield "Glad you're here!"
>>> chat_feed = ChatFeed(callback=say_welcome, header="Welcome Feed") >>> chat_feed.send("Hello World!", user="New User", avatar="😊")
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, css_classes, design, height, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.layout.base.ListPanel
: scrollmargin
= param.Margin(allow_None=True, allow_refs=True, default=5, label=’Margin’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1204e6450>)Allows to create additional space around the component. May be specified as a two-tuple of the form (vertical, horizontal) or a four-tuple (top, right, bottom, left).
objects
= param.Children(allow_refs=False, bounds=(0, None), class_=<class ‘panel.viewable.Viewable’>, default=[], item_type=<class ‘panel.viewable.Viewable’>, label=’Objects’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1272d3310>)The list of child objects that make up the layout.
auto_scroll_limit
= param.Integer(allow_refs=False, bounds=(0, None), default=200, inclusive_bounds=(True, True), label=’Auto scroll limit’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12734b050>)Max pixel distance from the latest object in the Column to activate automatic scrolling upon update. Setting to 0 disables auto-scrolling.
callback
= param.Callable(allow_None=True, allow_refs=False, label=’Callback’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120cbecd0>)Callback to execute when a user sends a message or when respond is called. The signature must include the previous message value contents, the previous user name, and the component instance.
callback_exception
= param.ObjectSelector(allow_refs=False, default=’summary’, label=’Callback exception’, names={}, nested_refs=False, objects=[‘raise’, ‘summary’, ‘verbose’, ‘ignore’], rx=<param.reactive.reactive_ops object at 0x12725f950>)How to handle exceptions raised by the callback. If “raise”, the exception will be raised. If “summary”, a summary will be sent to the chat feed. If “verbose”, the full traceback will be sent to the chat feed. If “ignore”, the exception will be ignored.
callback_user
= param.String(allow_refs=False, default=’Assistant’, label=’Callback user’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120d4d990>)The default user name to use for the message provided by the callback.
callback_avatar
= param.ClassSelector(allow_None=True, allow_refs=False, class_=(<class ‘str’>, <class ‘_io.BytesIO’>, <class ‘bytes’>, <class ‘panel.pane.image.ImageBase’>), label=’Callback avatar’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127346b50>)The default avatar to use for the entry provided by the callback. Takes precedence over ChatMessage.default_avatars if set; else, if None, defaults to the avatar set in ChatMessage.default_avatars if matching key exists. Otherwise defaults to the first character of the callback_user.
card_params
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’Card params’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127370f50>)Params to pass to Card, like header, header_background, header_color, etc.
collapsible
= param.Boolean(allow_refs=False, constant=True, default=False, label=’Collapsible’, nested_refs=False, readonly=True, rx=<param.reactive.reactive_ops object at 0x1207dc1d0>)Whether the Card should be expandable and collapsible.
disabled
= param.Boolean(allow_refs=False, default=False, label=’Disabled’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120da45d0>)Whether the feed is disabled.
message_params
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’Message params’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127345d50>)Params to pass to each ChatMessage, like reaction_icons, timestamp_format, show_avatar, show_user, and show_timestamp. Params passed that are not ChatFeed params will be forwarded into message_params.
header
= param.Parameter(allow_None=True, allow_refs=False, label=’Header’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120df2150>)The header of the chat feed; commonly used for the title. Can be a string, pane, or widget.
help_text
= param.String(allow_refs=False, default=’’, label=’Help text’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1204e6450>)If provided, initializes a chat message in the chat log using the provided help text as the message object and help as the user. This is useful for providing instructions, and will not be included in the serialize method by default.
load_buffer
= param.Integer(allow_refs=False, bounds=(0, None), default=50, inclusive_bounds=(True, True), label=’Load buffer’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127371750>)The number of objects loaded on each side of the visible objects. When scrolled halfway into the buffer, the feed will automatically load additional objects while unloading objects on the opposite side.
placeholder_text
= param.String(allow_refs=False, default=’’, label=’Placeholder text’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127345d50>)The text to display next to the placeholder icon.
placeholder_params
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={‘user’: ‘ ‘, ‘reaction_icons’: {}, ‘show_copy_icon’: False, ‘show_timestamp’: False}, label=’Placeholder params’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12725f950>)Params to pass to the placeholder ChatMessage, like reaction_icons, timestamp_format, show_avatar, show_user, show_timestamp.
placeholder_threshold
= param.Number(allow_refs=False, bounds=(0, None), default=1, inclusive_bounds=(True, True), label=’Placeholder threshold’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11d4a2890>)Min duration in seconds of buffering before displaying the placeholder. If 0, the placeholder will be disabled.
post_hook
= param.Callable(allow_None=True, allow_refs=False, label=’Post hook’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120d4d990>)A hook to execute after a new message is completely added, i.e. the generator is exhausted. The stream method will trigger this callback on every call. The signature must include the message and instance arguments.
renderers
= param.HookList(allow_refs=False, bounds=(0, None), default=[], label=’Renderers’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1207dc1d0>)A callable or list of callables that accept the value and return a Panel object to render the value. If a list is provided, will attempt to use the first renderer that does not raise an exception. If None, will attempt to infer the renderer from the value.
scroll_button_threshold
= param.Integer(allow_refs=False, bounds=(0, None), default=100, inclusive_bounds=(True, True), label=’Scroll button threshold’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11d47ed90>)Min pixel distance from the latest object in the Column to display the scroll button. Setting to 0 disables the scroll button.
show_activity_dot
= param.Boolean(allow_refs=False, default=True, label=’Show activity dot’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120b15490>)Whether to show an activity dot on the ChatMessage while streaming the callback response.
view_latest
= param.Boolean(allow_refs=False, default=True, label=’View latest’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12725f950>)Whether to scroll to the latest object on init. If not enabled the view will be on the first object.
_placeholder
= param.ClassSelector(allow_None=True, allow_refs=False, class_=<class ‘panel.chat.message.ChatMessage’>, label=’ placeholder’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120777790>)The placeholder wrapped in a ChatMessage object; primarily to prevent recursion error in _update_placeholder.
_callback_state
= param.ObjectSelector(allow_refs=False, label=’ callback state’, names={}, nested_refs=False, objects=[<CallbackState.IDLE: ‘idle’>, <CallbackState.RUNNING: ‘running’>, <CallbackState.GENERATING: ‘generating’>, <CallbackState.STOPPING: ‘stopping’>, <CallbackState.STOPPED: ‘stopped’>], rx=<param.reactive.reactive_ops object at 0x12084f050>)The current state of the callback.
_prompt_trigger
= param.Event(allow_refs=False, default=False, label=’ prompt trigger’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12152f590>)Triggers the prompt input.
_callback_trigger
= param.Event(allow_refs=False, default=False, label=’ callback trigger’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11d4a2890>)Triggers the callback to respond.
_post_hook_trigger
= param.Event(allow_refs=False, default=False, label=’ post hook trigger’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x11f42b910>)Triggers the append callback.
_disabled_stack
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’ disabled stack’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x120fda250>)The previous disabled state of the feed.
- add_step(step: str | list[str] | ChatStep | None = None, append: bool = True, user: str | None = None, avatar: str | bytes | BytesIO | None = None, steps_layout: Column | Card | None = None, default_layout: Literal['column', 'card'] = 'card', layout_params: dict | None = None, **step_params) ChatStep [source]#
Adds a ChatStep component either by appending it to an existing ChatMessage or creating a new ChatMessage.
Arguments#
- stepstr | list(str) | ChatStep | None
The objects to stream to the step.
- appendbool
Whether to append to existing steps or create new steps.
- userstr | None
The user to stream as; overrides the message’s user if provided. Will default to the user parameter. Only applicable if steps is “new”.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message’s avatar if provided. Will default to the avatar parameter. Only applicable if steps is “new”.
- steps_layoutColumn | None
An existing layout of steps to stream to, if None is provided it will default to the last Column of steps or create a new one.
- default_layoutstr
The default layout to use if steps_layout is None. ‘column’ will create a new Column layout. ‘card’ will create a new Card layout.
- layout_paramsdict | None
Additional parameters to pass to the layout.
- step_paramsdict
Parameters to pass to the ChatStep.
- append(obj: Any) None [source]#
Appends an object to the layout.
Arguments#
obj (object): Panel component to add to the layout.
- clear() list[Any] [source]#
Clears the chat log and returns the messages that were cleared.
Returns#
The messages that were cleared.
- clone(*objects: Any, **params: Any) ListLike [source]#
Makes a copy of the layout sharing the same parameters.
Arguments#
objects: Objects to add to the cloned layout. params: Keyword arguments override the parameters on the clone.
Returns#
Cloned layout object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- extend(objects: Iterable[Any]) None [source]#
Extends the objects on this layout with a list.
Arguments#
objects (list): List of panel components to add to the layout.
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- index(object) int [source]#
Returns the integer index of the supplied object in the list of objects.
Arguments#
obj (object): Panel component to look up the index for.
Returns#
index (int): Integer index of the object in the layout.
- insert(index: int, obj: Any) None [source]#
Inserts an object in the layout at the specified index.
Arguments#
index (int): Index at which to insert the object. object (object): Panel components to insert in the layout.
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- pop(index: int) Viewable [source]#
Pops an item from the layout by index.
Arguments#
index (int): The index of the item to pop from the layout.
- prompt_user(component: Widget | ListPanel, callback: Callable | None = None, predicate: Callable | None = None, timeout: int = 120, timeout_message: str = 'Timed out', button_params: dict | None = None, timeout_button_params: dict | None = None, **send_kwargs) None [source]#
Prompts the user to interact with a form component.
Arguments#
- componentWidget | ListPanel
The component to prompt the user with.
- callbackCallable
The callback to execute once the user submits the form. The callback should accept two arguments: the component and the ChatFeed instance.
- predicateCallable | None
A predicate to evaluate the component’s state, e.g. widget has value. If provided, the button will be enabled when the predicate returns True. The predicate should accept the component as an argument.
- timeoutint
The duration in seconds to wait before timing out.
- timeout_messagestr
The message to display when the timeout is reached.
- button_paramsdict | None
Additional parameters to pass to the submit button.
- timeout_button_paramsdict | None
Additional parameters to pass to the timeout button.
- remove(obj: Viewable) None [source]#
Removes an object from the layout.
Arguments#
obj (object): The object to remove from the layout.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector=None)[source]#
Iterates over the ChatInterface and any potential children in the applying the selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- send(value: ChatMessage | dict | Any, user: str | None = None, avatar: str | bytes | BytesIO | None = None, respond: bool = True, **message_params) ChatMessage | None [source]#
Sends a value and creates a new message in the chat log.
If respond is True, additionally executes the callback, if provided.
Arguments#
- valueChatMessage | dict | Any
The message contents to send.
- userstr | None
The user to send as; overrides the message message’s user if provided.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message message’s avatar if provided.
- respondbool
Whether to execute the callback.
- message_paramsdict
Additional parameters to pass to the ChatMessage.
Returns#
The message that was created.
- serialize(exclude_users: list[str] | None = None, filter_by: Callable | None = None, format: Literal['transformers'] = 'transformers', custom_serializer: Callable | None = None, limit: int | None = None, **serialize_kwargs)[source]#
Exports the chat log.
Arguments#
- formatstr
The format to export the chat log as; currently only supports “transformers”.
- exclude_userslist(str) | None
A list of user (case insensitive names) to exclude from serialization. If not provided, defaults to [“help”]. This will be executed before filter_by.
- filter_bycallable
A function to filter the chat log by. The function must accept and return a list of ChatMessage objects.
- custom_serializercallable
A custom function to format the ChatMessage’s object. The function must accept one positional argument, the ChatMessage object, and return a string. If not provided, uses the serialize method on ChatMessage.
- limitint
The number of messages to serialize at most, starting from the last message.
- **serialize_kwargs
Additional keyword arguments to use for the specified format.
format=”transformers” role_names : dict(str, str | list(str)) | None
A dictionary mapping the role to the ChatMessage’s user name. Defaults to {“user”: [“user”], “assistant”: [self.callback_user]} if not set. The keys and values are case insensitive as the strings will all be lowercased. The values can be a string or a list of strings, e.g. {“user”: “user”, “assistant”: [“executor”, “langchain”]}.
- default_rolestr
The default role to use if the user name is not found in role_names. If this is set to None, raises a ValueError if the user name is not found.
Returns#
The chat log serialized in the specified format.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- stop() bool [source]#
Cancels the current callback task if possible.
Returns#
Whether the task was successfully stopped or done.
- stream(value: str | dict | ChatMessage, user: str | None = None, avatar: str | bytes | BytesIO | None = None, message: ChatMessage | None = None, replace: bool = False, **message_params) ChatMessage | None [source]#
Streams a token and updates the provided message, if provided. Otherwise creates a new message in the chat log, so be sure the returned message is passed back into the method, e.g. message = chat.stream(token, message=message).
This method is primarily for outputs that are not generators– notably LangChain. For most cases, use the send method instead.
Arguments#
- valuestr | dict | ChatMessage
The new token value to stream.
- userstr | None
The user to stream as; overrides the message’s user if provided.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message’s avatar if provided.
- messageChatMessage | None
The message to update.
- replacebool
Whether to replace the existing text when streaming a string or dict.
- message_paramsdict
Additional parameters to pass to the ChatMessage.
Returns#
The message that was updated.
icon
Module#
The icon module provides a low-level API for rendering chat related icons.
- class panel.chat.icon.ChatCopyIcon(*, _request_sync, _synced, fill, value, loading, align, aspect_ratio, css_classes, design, height, height_policy, margin, max_height, max_width, min_height, min_width, sizing_mode, styles, stylesheets, tags, visible, width, width_policy, name)[source]#
Bases:
ReactiveHTML
ChatCopyIcon copies the value to the clipboard when clicked. To avoid sending the value to the frontend the value is only synced after the icon is clicked.
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, design, height, min_width, min_height, max_width, max_height, margin, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingcss_classes
= param.List(allow_refs=True, bounds=(0, None), default=[‘copy-icon’], label=’Css classes’, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x1275361d0>)The CSS classes of the widget.
fill
= param.String(allow_refs=False, default=’none’, label=’Fill’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12755d8d0>)The fill color of the icon.
value
= param.String(allow_None=True, allow_refs=False, label=’Value’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127532a90>)The text to copy to the clipboard.
_synced
= param.String(allow_None=True, allow_refs=False, label=’ synced’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12755d450>)The text to copy to the clipboard.
_request_sync
= param.Integer(allow_refs=False, default=0, inclusive_bounds=(True, True), label=’ request sync’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12755dfd0>)- clone(**params) Viewable [source]#
Makes a copy of the object sharing the same parameters.
Arguments#
params: Keyword arguments override the parameters on the clone.
Returns#
Cloned Viewable object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- on_event(node: str, event: str, callback: Callable) None [source]#
Registers a callback to be executed when the specified DOM event is triggered on the named node. Note that the named node must be declared in the HTML. To create a named node you must give it an id of the form id=”name”, where name will be the node identifier.
Arguments#
- node: str
Named node in the HTML identifiable via id of the form id=”name”.
- event: str
Name of the DOM event to add an event listener to.
- callback: callable
A callable which will be given the DOMEvent object.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- class panel.chat.icon.ChatReactionIcons(*, active_icons, default_layout, options, disabled, loading, align, aspect_ratio, css_classes, design, height, height_policy, margin, max_height, max_width, min_height, min_width, sizing_mode, styles, stylesheets, tags, visible, width, width_policy, value, name)[source]#
Bases:
CompositeWidget
A widget to display reaction icons that can be clicked on.
Parameters#
- valueList
The selected reactions.
- optionsDict
A key-value pair of reaction values and their corresponding tabler icon names found on https://tabler-icons.io.
- active_iconsDict
The mapping of reactions to their corresponding active icon names; if not set, the active icon name will default to its “filled” version.
Reference: https://panel.holoviz.org/reference/chat/ChatReactionIcons.html
- Example:
>>> ChatReactionIcons(value=["like"], options={"like": "thumb-up", "dislike": "thumb-down"})
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, design, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.widgets.base.Widget
: height, width, disabledvalue
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Value’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12777ba10>)The active reactions.
css_classes
= param.List(allow_refs=True, bounds=(0, None), default=[‘reaction-icons’], label=’Css classes’, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x127781790>)The CSS classes of the widget.
margin
= param.Margin(allow_None=True, allow_refs=True, default=0, label=’Margin’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12777af50>)Allows to create additional space around the component. May be specified as a two-tuple of the form (vertical, horizontal) or a four-tuple (top, right, bottom, left).
active_icons
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’Active icons’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12777bf10>)The mapping of reactions to their corresponding active icon names. If not set, the active icon name will default to its “filled” version.
options
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={‘favorite’: ‘heart’}, label=’Options’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12777af50>)A key-value pair of reaction values and their corresponding tabler icon names found on https://tabler-icons.io.
default_layout
= param.ClassSelector(allow_refs=False, class_=<class ‘panel.layout.base.Panel’>, default=<class ‘panel.layout.base.Column’>, label=’Default layout’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x12777bf90>)- clone(**params) Viewable [source]#
Makes a copy of the object sharing the same parameters.
Arguments#
params: Keyword arguments override the parameters on the clone.
Returns#
Cloned Viewable object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- classmethod from_param(parameter: param.Parameter, **params) T [source]#
Construct a widget from a Parameter and link the two bi-directionally.
Parameters#
- parameter: param.Parameter
A parameter to create the widget from.
Returns#
Widget instance linked to the supplied parameter
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
input
Module#
- class panel.chat.input.ChatAreaInput(**params: Any)[source]#
Bases:
TextAreaInput
The ChatAreaInput allows entering any multiline string using a text input box, with the ability to press enter to submit the message.
Unlike TextAreaInput, the ChatAreaInput defaults to auto_grow=True and max_rows=10, and the value is not synced to the server until the enter key is pressed so bind on value_input if you need to access the existing value.
Lines are joined with the newline character n.
Reference: https://panel.holoviz.org/reference/chat/ChatAreaInput.html
- Example:
>>> ChatAreaInput(max_rows=10)
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, css_classes, design, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.widgets.base.Widget
: height, margin, disabledpanel.widgets.input._TextInputBase
: value, width, description, max_length, placeholder, value_inputauto_grow
= param.Boolean(allow_refs=False, default=True, label=’Auto grow’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127befa10>)Whether the text area should automatically grow vertically to accommodate the current text.
max_rows
= param.Integer(allow_refs=False, default=10, inclusive_bounds=(True, True), label=’Max rows’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127a0d9d0>)When combined with auto_grow this determines the maximum number of rows the input area can grow.
rows
= param.Integer(allow_refs=False, default=1, inclusive_bounds=(True, True), label=’Rows’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127beb150>)Number of rows in the text input field.
resizable
= param.ObjectSelector(allow_refs=False, default=’height’, label=’Resizable’, names={}, nested_refs=False, objects=[‘both’, ‘width’, ‘height’, False], rx=<param.reactive.reactive_ops object at 0x127797950>)Whether the layout is interactively resizable, and if so in which dimensions: width, height, or both. Can only be set during initialization.
disabled_enter
= param.Boolean(allow_refs=False, default=False, label=’Disabled enter’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127bef990>)If True, disables sending the message by pressing the enter_sends key.
enter_sends
= param.Boolean(allow_refs=False, default=True, label=’Enter sends’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127bea8d0>)If True, pressing the Enter key sends the message, if False it is sent by pressing the Ctrl+Enter.
- clone(**params) Viewable [source]#
Makes a copy of the object sharing the same parameters.
Arguments#
params: Keyword arguments override the parameters on the clone.
Returns#
Cloned Viewable object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- classmethod from_param(parameter: param.Parameter, onkeyup=False, **params) Viewable [source]#
Construct a widget from a Parameter and link the two bi-directionally.
Parameters#
- parameter: param.Parameter
A parameter to create the widget from.
- onkeyup: boolean
Whether to trigger events on every key press.
- params: dict
Keyword arguments to be passed to the widget constructor
Returns#
Widget instance linked to the supplied parameter
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
interface
Module#
The interface module provides an even higher-level API for interacting with a list of ChatMessage objects compared to the ChatFeed through a frontend input UI.
- class panel.chat.interface.ChatInterface(*objects, **params)[source]#
Bases:
ChatFeed
High level widget that contains the chat log and the chat input.
Reference: https://panel.holoviz.org/reference/chat/ChatInterface.html
- Example:
>>> async def repeat_contents(contents, user, instance): >>> yield contents
>>> chat_interface = ChatInterface( callback=repeat_contents, widgets=[TextInput(), FileInput()] )
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, css_classes, design, height, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.layout.base.ListPanel
: scrollpanel.chat.feed.ChatFeed
: margin, objects, auto_scroll_limit, callback, callback_exception, callback_user, callback_avatar, card_params, collapsible, disabled, message_params, header, help_text, load_buffer, placeholder_text, placeholder_params, placeholder_threshold, post_hook, renderers, scroll_button_threshold, show_activity_dot, view_latest, _placeholder, _callback_state, _prompt_trigger, _callback_trigger, _post_hook_trigger, _disabled_stackauto_send_types
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Auto send types’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db1dd0>)The widget types to automatically send when the user presses enter or clicks away from the widget. If not provided, defaults to [TextInput].
avatar
= param.ClassSelector(allow_None=True, allow_refs=False, class_=(<class ‘str’>, <class ‘_io.BytesIO’>, <class ‘bytes’>, <class ‘panel.pane.image.ImageBase’>), label=’Avatar’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127d2c650>)The avatar to use for the user. Can be a single character text, an emoji, or anything supported by pn.pane.Image. If not set, uses the first character of the name.
reset_on_send
= param.Boolean(allow_refs=False, default=True, label=’Reset on send’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db2710>)Whether to reset the widget’s value after sending a message; has no effect for TextInput.
show_send
= param.Boolean(allow_refs=False, default=True, label=’Show send’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db05d0>)Whether to show the send button.
show_stop
= param.Boolean(allow_refs=False, default=True, label=’Show stop’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db1d50>)Whether to show the stop button temporarily replacing the send button during callback; has no effect if callback is not async.
show_rerun
= param.Boolean(allow_refs=False, default=True, label=’Show rerun’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db05d0>)Whether to show the rerun button.
show_undo
= param.Boolean(allow_refs=False, default=True, label=’Show undo’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db1bd0>)Whether to show the undo button.
show_clear
= param.Boolean(allow_refs=False, default=True, label=’Show clear’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db05d0>)Whether to show the clear button.
show_button_name
= param.Boolean(allow_None=True, allow_refs=False, label=’Show button name’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db2690>)Whether to show the button name.
user
= param.String(allow_refs=False, default=’User’, label=’User’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127a5ff90>)Name of the ChatInterface user.
widgets
= param.ClassSelector(allow_None=True, allow_refs=False, class_=(<class ‘panel.widgets.base.WidgetBase’>, <class ‘list’>), label=’Widgets’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db2050>)Widgets to use for the input. If not provided, defaults to [TextInput].
button_properties
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’Button properties’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db0910>)Allows addition of functionality or customization of buttons by supplying a mapping from the button name to a dictionary containing the icon, callback, post_callback, and/or js_on_click keys. If the button names correspond to default buttons (send, rerun, undo, clear), the default icon can be updated and if a callback key value pair is provided, the specified callback functionality runs before the existing one. For button names that don’t match existing ones, new buttons are created and must include a callback, post_callback, and/or js_on_click key. The provided callbacks should have a signature that accepts two positional arguments: instance (the ChatInterface instance) and event (the button click event). The js_on_click key should be a str or dict. If str, provide the JavaScript code; else if dict, it must have a code key, containing the JavaScript code to execute when the button is clicked, and optionally an args key, containing dictionary of arguments to pass to the JavaScript code.
_widgets
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’ widgets’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db2050>)The input widgets.
_input_container
= param.ClassSelector(allow_None=True, allow_refs=False, class_=<class ‘panel.layout.base.Row’>, label=’ input container’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db0990>)The input message row that wraps the input layout (Tabs / Row) to easily swap between Tabs and Rows, depending on number of widgets.
_input_layout
= param.ClassSelector(allow_None=True, allow_refs=False, class_=(<class ‘panel.layout.base.Row’>, <class ‘panel.layout.tabs.Tabs’>), label=’ input layout’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db2050>)The input layout that contains the input widgets.
_button_data
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’ button data’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db0990>)Metadata and data related to the buttons.
_buttons
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={}, label=’ buttons’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127db1d50>)The rendered buttons.
- property active: int#
The currently active input widget tab index; -1 if there is only one widget available which is not in a tab.
Returns#
The active input widget tab index.
- property active_widget: WidgetBase#
The currently active widget.
Returns#
The active widget.
- add_step(step: str | list[str] | ChatStep | None = None, append: bool = True, user: str | None = None, avatar: str | bytes | BytesIO | None = None, steps_layout: Column | Card | None = None, default_layout: Literal['column', 'card'] = 'card', layout_params: dict | None = None, **step_params) ChatStep [source]#
Adds a ChatStep component either by appending it to an existing ChatMessage or creating a new ChatMessage.
Arguments#
- stepstr | list(str) | ChatStep | None
The objects to stream to the step.
- appendbool
Whether to append to existing steps or create new steps.
- userstr | None
The user to stream as; overrides the message’s user if provided. Will default to the user parameter. Only applicable if steps is “new”.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message’s avatar if provided. Will default to the avatar parameter. Only applicable if steps is “new”.
- steps_layoutColumn | None
An existing layout of steps to stream to, if None is provided it will default to the last Column of steps or create a new one.
- default_layoutstr
The default layout to use if steps_layout is None. ‘column’ will create a new Column layout. ‘card’ will create a new Card layout.
- layout_paramsdict | None
Additional parameters to pass to the layout.
- step_paramsdict
Parameters to pass to the ChatStep.
- append(obj: Any) None [source]#
Appends an object to the layout.
Arguments#
obj (object): Panel component to add to the layout.
- clear() list[Any] [source]#
Clears the chat log and returns the messages that were cleared.
Returns#
The messages that were cleared.
- clone(*objects: Any, **params: Any) ListLike [source]#
Makes a copy of the layout sharing the same parameters.
Arguments#
objects: Objects to add to the cloned layout. params: Keyword arguments override the parameters on the clone.
Returns#
Cloned layout object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- extend(objects: Iterable[Any]) None [source]#
Extends the objects on this layout with a list.
Arguments#
objects (list): List of panel components to add to the layout.
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- index(object) int [source]#
Returns the integer index of the supplied object in the list of objects.
Arguments#
obj (object): Panel component to look up the index for.
Returns#
index (int): Integer index of the object in the layout.
- insert(index: int, obj: Any) None [source]#
Inserts an object in the layout at the specified index.
Arguments#
index (int): Index at which to insert the object. object (object): Panel components to insert in the layout.
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- pop(index: int) Viewable [source]#
Pops an item from the layout by index.
Arguments#
index (int): The index of the item to pop from the layout.
- prompt_user(component: Widget | ListPanel, callback: Callable | None = None, predicate: Callable | None = None, timeout: int = 120, timeout_message: str = 'Timed out', button_params: dict | None = None, timeout_button_params: dict | None = None, **send_kwargs) None [source]#
Prompts the user to interact with a form component.
Arguments#
- componentWidget | ListPanel
The component to prompt the user with.
- callbackCallable
The callback to execute once the user submits the form. The callback should accept two arguments: the component and the ChatFeed instance.
- predicateCallable | None
A predicate to evaluate the component’s state, e.g. widget has value. If provided, the button will be enabled when the predicate returns True. The predicate should accept the component as an argument.
- timeoutint
The duration in seconds to wait before timing out.
- timeout_messagestr
The message to display when the timeout is reached.
- button_paramsdict | None
Additional parameters to pass to the submit button.
- timeout_button_paramsdict | None
Additional parameters to pass to the timeout button.
- remove(obj: Viewable) None [source]#
Removes an object from the layout.
Arguments#
obj (object): The object to remove from the layout.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector=None)[source]#
Iterates over the ChatInterface and any potential children in the applying the selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- send(value: ChatMessage | dict | Any, user: str | None = None, avatar: str | bytes | BytesIO | None = None, respond: bool = True, **message_params) ChatMessage | None [source]#
Sends a value and creates a new message in the chat log.
If respond is True, additionally executes the callback, if provided.
Arguments#
- valueChatMessage | dict | Any
The message contents to send.
- userstr | None
The user to send as; overrides the message message’s user if provided. Will default to the user parameter.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message message’s avatar if provided. Will default to the avatar parameter.
- respondbool
Whether to execute the callback.
- message_paramsdict
Additional parameters to pass to the ChatMessage.
Returns#
The message that was created.
- serialize(exclude_users: list[str] | None = None, filter_by: Callable | None = None, format: Literal['transformers'] = 'transformers', custom_serializer: Callable | None = None, limit: int | None = None, **serialize_kwargs)[source]#
Exports the chat log.
Arguments#
- formatstr
The format to export the chat log as; currently only supports “transformers”.
- exclude_userslist(str) | None
A list of user (case insensitive names) to exclude from serialization. If not provided, defaults to [“help”]. This will be executed before filter_by.
- filter_bycallable
A function to filter the chat log by. The function must accept and return a list of ChatMessage objects.
- custom_serializercallable
A custom function to format the ChatMessage’s object. The function must accept one positional argument, the ChatMessage object, and return a string. If not provided, uses the serialize method on ChatMessage.
- limitint
The number of messages to serialize at most, starting from the last message.
- **serialize_kwargs
Additional keyword arguments to use for the specified format.
format=”transformers” role_names : dict(str, str | list(str)) | None
A dictionary mapping the role to the ChatMessage’s user name. Defaults to {“user”: [“user”], “assistant”: [self.callback_user]} if not set. The keys and values are case insensitive as the strings will all be lowercased. The values can be a string or a list of strings, e.g. {“user”: “user”, “assistant”: [“executor”, “langchain”]}.
- default_rolestr
The default role to use if the user name is not found in role_names. If this is set to None, raises a ValueError if the user name is not found.
Returns#
The chat log serialized in the specified format.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- stop() bool [source]#
Cancels the current callback task if possible.
Returns#
Whether the task was successfully stopped or done.
- stream(value: str | dict | ChatMessage, user: str | None = None, avatar: str | bytes | BytesIO | None = None, message: ChatMessage | None = None, replace: bool = False, **message_params) ChatMessage | None [source]#
Streams a token and updates the provided message, if provided. Otherwise creates a new message in the chat log, so be sure the returned message is passed back into the method, e.g. message = chat.stream(token, message=message).
This method is primarily for outputs that are not generators– notably LangChain. For most cases, use the send method instead.
Arguments#
- valuestr | dict | ChatMessage
The new token value to stream.
- userstr | None
The user to stream as; overrides the message’s user if provided. Will default to the user parameter.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message’s avatar if provided. Will default to the avatar parameter.
- messageChatMessage | None
The message to update.
- replacebool
Whether to replace the existing text when streaming a string or dict.
- message_paramsdict
Additional parameters to pass to the ChatMessage.
Returns#
The message that was updated.
langchain
Module#
The langchain module integrates Langchain support with Panel.
- class panel.chat.langchain.PanelCallbackHandler(instance: ChatFeed | ChatInterface, user: str = 'LangChain', avatar: str = '🦜')[source]#
Bases:
object
The Langchain PanelCallbackHandler itself is not a widget or pane, but is useful for rendering and streaming the chain of thought from Langchain Tools, Agents, and Chains as ChatMessage objects.
Reference: https://panel.holoviz.org/reference/chat/PanelCallbackHandler.html
- Example:
>>> chat_interface = pn.widgets.ChatInterface(callback=callback, callback_user="Langchain") >>> callback_handler = pn.widgets.langchain.PanelCallbackHandler(instance=chat_interface) >>> llm = ChatOpenAI(streaming=True, callbacks=[callback_handler]) >>> chain = ConversationChain(llm=llm)
- on_chat_model_start(serialized: dict[str, Any], messages: list, **kwargs: Any) None [source]#
To prevent the inherited class from raising NotImplementedError, will not call super() here.
message
Module#
The message module provides a low-level API for rendering chat messages.
- class panel.chat.message.ChatMessage(object=None, **params)[source]#
Bases:
Pane
Renders another component as a chat message with an associated user and avatar with support for various content types.
This widget provides a structured view of chat messages, including features like:
Displaying user avatars, which can be text, emoji, or images.
Showing the user’s name.
Displaying the message timestamp in a customizable format.
Associating reactions with messages and mapping them to icons.
Rendering various content types including text, images, audio, video, and more.
Reference: https://panel.holoviz.org/reference/chat/ChatMessage.html
- Example:
>>> ChatMessage(object="Hello world!", user="New User", avatar="😊")
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, design, height, min_width, min_height, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.pane.base.PaneBase
: margin, default_layoutcss_classes
= param.List(allow_refs=True, bounds=(0, None), default=[‘chat-message’], label=’Css classes’, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x127fc2dd0>)The CSS classes to apply to the widget.
max_width
= param.Integer(allow_None=True, allow_refs=True, bounds=(0, None), default=1200, inclusive_bounds=(True, True), label=’Max width’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127c7d9d0>)Minimal width of the component (in pixels) if width is adjustable.
object
= param.Parameter(allow_None=True, allow_refs=False, label=’Object’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc1550>)The message contents. Can be any Python object that panel can display.
avatar
= param.ClassSelector(allow_refs=False, class_=(<class ‘str’>, <class ‘_io.BytesIO’>, <class ‘bytes’>, <class ‘panel.pane.image.ImageBase’>), default=’’, label=’Avatar’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc0350>)The avatar to use for the user. Can be a single character text, an emoji, or anything supported by pn.pane.Image. If not set, checks if the user is available in the default_avatars mapping; else uses the first character of the name.
avatar_lookup
= param.Callable(allow_None=True, allow_refs=False, label=’Avatar lookup’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1211f4ad0>)A function that can lookup an avatar from a user name. The function signature should be (user: str) -> Avatar. If this is set, default_avatars is disregarded.
default_avatars
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={‘client’: ‘🧑’, ‘customer’: ‘🧑’, ‘employee’: ‘🧑’, ‘human’: ‘🧑’, ‘person’: ‘🧑’, ‘user’: ‘🧑’, ‘agent’: ‘🤖’, ‘ai’: ‘🤖’, ‘assistant’: ‘🤖’, ‘bot’: ‘🤖’, ‘chatbot’: ‘🤖’, ‘machine’: ‘🤖’, ‘robot’: ‘🤖’, ‘system’: ‘⚙️’, ‘exception’: ‘❌’, ‘error’: ‘❌’, ‘help’: ‘❓’, ‘input’: ‘❗’, ‘adult’: ‘🧑’, ‘baby’: ‘👶’, ‘boy’: ‘👦’, ‘child’: ‘🧒’, ‘girl’: ‘👧’, ‘man’: ‘👨’, ‘woman’: ‘👩’, ‘chatgpt’: ‘{dist_path}assets/logo/gpt-3.svg’, ‘gpt3’: ‘{dist_path}assets/logo/gpt-3.svg’, ‘gpt4’: ‘{dist_path}assets/logo/gpt-4.svg’, ‘dalle’: ‘{dist_path}assets/logo/gpt-4.svg’, ‘openai’: ‘{dist_path}assets/logo/gpt-4.svg’, ‘huggingface’: ‘🤗’, ‘calculator’: ‘🧮’, ‘langchain’: ‘🦜’, ‘retriever’: ‘📄’, ‘tool’: ‘🛠️’, ‘translator’: ‘🌐’, ‘wolfram’: ‘{dist_path}assets/logo/wolfram.svg’, ‘wolfram alpha’: ‘{dist_path}assets/logo/wolfram.svg’, ‘llama’: ‘🦙’, ‘llama2’: ‘🐪’, ‘plot’: ‘📊’, ‘lumen’: ‘{dist_path}assets/logo/lumen.svg’, ‘holoviews’: ‘{dist_path}assets/logo/holoviews.svg’, ‘hvplot’: ‘{dist_path}assets/logo/hvplot.svg’, ‘panel’: ‘{dist_path}images/icon-vector.svg’}, label=’Default avatars’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc0250>)A default mapping of user names to their corresponding avatars to use when the user is specified but the avatar is. You can modify, but not replace the dictionary.
footer_objects
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Footer objects’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc3010>)A list of objects to display in the column of the footer of the message.
header_objects
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Header objects’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc0ad0>)A list of objects to display in the row of the header of the message.
reactions
= param.List(allow_refs=False, bounds=(0, None), default=[], label=’Reactions’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc1c10>)Reactions to associate with the message.
reaction_icons
= param.ClassSelector(allow_None=True, allow_refs=False, class_=<class ‘panel.chat.icon.ChatReactionIcons’>, label=’Reaction icons’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc0350>)A mapping of reactions to their reaction icons; if not provided defaults to {“favorite”: “heart”}.
timestamp
= param.Date(allow_None=True, allow_refs=False, inclusive_bounds=(True, True), label=’Timestamp’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc3010>)Timestamp of the message. Defaults to the creation time.
timestamp_format
= param.String(allow_refs=False, default=’%H:%M’, label=’Timestamp format’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc3dd0>)The timestamp format.
timestamp_tz
= param.String(allow_None=True, allow_refs=False, label=’Timestamp tz’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127b21850>)The timezone to used for the creation timestamp; only applicable if timestamp is not set. If None, tries to use pn.state.browser_info.timezone, else, the default tz of datetime.datetime.now(); see zoneinfo.available_timezones() for a list of valid timezones.
show_avatar
= param.Boolean(allow_refs=False, default=True, label=’Show avatar’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc3f90>)Whether to display the avatar of the user.
show_user
= param.Boolean(allow_refs=False, default=True, label=’Show user’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1211f4ad0>)Whether to display the name of the user.
show_timestamp
= param.Boolean(allow_refs=False, default=True, label=’Show timestamp’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc1c10>)Whether to display the timestamp of the message.
show_reaction_icons
= param.Boolean(allow_refs=False, default=True, label=’Show reaction icons’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x1276a7010>)Whether to display the reaction icons.
show_copy_icon
= param.Boolean(allow_refs=False, default=True, label=’Show copy icon’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127fc0590>)Whether to display the copy icon.
show_activity_dot
= param.Boolean(allow_refs=False, default=False, label=’Show activity dot’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127f71250>)Whether to show the activity dot.
renderers
= param.HookList(allow_refs=False, bounds=(0, None), default=[], label=’Renderers’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127222090>)A callable or list of callables that accept the object and return a Panel object to render the object. If a list is provided, will attempt to use the first renderer that does not raise an exception. If None, will attempt to infer the renderer from the object.
user
= param.Parameter(allow_refs=False, default=’User’, label=’User’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x127f71250>)Name of the user who sent the message.
- classmethod applies(obj: Any) float | bool | None [source]#
Returns boolean or float indicating whether the Pane can render the object.
If the priority of the pane is set to None, this method may also be used to define a float priority depending on the object being rendered.
- clone(object: Any | None = None, **params) T [source]#
Makes a copy of the Pane sharing the same parameters.
Arguments#
object: Optional new object to render params: Keyword arguments override the parameters on the clone.
Returns#
Cloned Pane object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- classmethod get_pane_type(obj: Any, **kwargs) type[PaneBase] [source]#
Returns the applicable Pane type given an object by resolving the precedence of all types whose applies method declares that the object is supported.
Arguments#
obj (object): The object type to return a Pane type for
Returns#
The applicable Pane type with the highest precedence.
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.document.Document
Optional Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: bool (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- serialize(prefix_with_viewable_label: bool = True, prefix_with_container_label: bool = True) str [source]#
Format the object to a string.
Arguments#
- prefix_with_viewable_labelbool
Whether to include the name of the Viewable, or type of the viewable if no name is specified.
- prefix_with_container_labelbool
Whether to include the name of the container, or type of the container if no name is specified.
Returns#
- str
The serialized string.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- stream(token: str, replace: bool = False)[source]#
Updates the message with the new token traversing the object to allow updating nested objects. When traversing a nested Panel the last object that supports rendering strings is updated, e.g. in a layout of Column(Markdown(…), Image(…)) the Markdown pane is updated.
Arguments#
- token: str
The token to stream to the text pane.
- replace: bool (default=False)
Whether to replace the existing text.
- update(value: dict | ChatMessage | Any, user: str | None = None, avatar: str | bytes | BytesIO | None = None)[source]#
Updates the message with a new value, user and avatar.
Arguments#
- valueChatMessage | dict | Any
The message contents to send.
- userstr | None
The user to send as; overrides the message message’s user if provided.
- avatarstr | bytes | BytesIO | None
The avatar to use; overrides the message message’s avatar if provided.
step
Module#
- class panel.chat.step.ChatStep(*objects, **params)[source]#
Bases:
Card
A component that makes it easy to provide status updates and the ability to stream updates to both the output(s) and the title.
Reference: https://panel.holoviz.org/reference/chat/ChatStep.html
- Example:
>>> ChatStep("Hello world!", title="Running calculation...', status="running")
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, design, height, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.layout.base.ListLike
: objectspanel.layout.base.ListPanel
: scrollpanel.layout.base.Column
: auto_scroll_limit, scroll_button_threshold, scroll_position, view_latestpanel.layout.card.Card
: css_classes, active_header_background, button_css_classes, collapsible, header_background, header_color, header_css_classes, hide_header, title_css_classesmargin
= param.Parameter(allow_refs=True, default=(5, 5, 5, 10), label=’Margin’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018dad0>)Allows to create additional space around the component. May be specified as a two-tuple of the form (vertical, horizontal) or a four-tuple (top, right, bottom, left).
collapsed
= param.Boolean(allow_refs=False, default=False, label=’Collapsed’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018e4d0>)Whether the contents of the Card are collapsed.
header
= param.Parameter(allow_None=True, allow_refs=False, constant=True, label=’Header’, nested_refs=False, readonly=True, rx=<param.reactive.reactive_ops object at 0x13018d910>)A Panel component to display in the header bar of the Card. Will override the given title if defined.
title
= param.String(allow_refs=False, constant=True, default=’’, label=’Title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018d850>)The title of the chat step. Will redirect to default_title on init. After, it cannot be set directly; instead use the *_title params.
collapsed_on_success
= param.Boolean(allow_refs=False, default=True, label=’Collapsed on success’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018d4d0>)Whether to collapse the card on completion.
context_exception
= param.ObjectSelector(allow_refs=False, default=’raise’, label=’Context exception’, names={}, nested_refs=False, objects=[‘raise’, ‘summary’, ‘verbose’, ‘ignore’], rx=<param.reactive.reactive_ops object at 0x13018d590>)How to handle exceptions raised upon exiting the context manager. If “raise”, the exception will be raised. If “summary”, a summary will be sent to the chat step. If “verbose”, the full traceback will be sent to the chat step. If “ignore”, the exception will be ignored.
success_title
= param.String(allow_None=True, allow_refs=False, label=’Success title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018db10>)Title to display when status is success.
default_badges
= param.Dict(allow_refs=False, class_=<class ‘dict’>, default={‘pending’: BooleanStatus(color=’primary’, margin=0), ‘running’: BooleanStatus(color=’warning’, margin=0, value=True), ‘success’: BooleanStatus(color=’success’, margin=0, value=True), ‘failed’: BooleanStatus(color=’danger’, margin=0, value=True)}, label=’Default badges’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018d850>)Mapping from status to default status badge; keys must be one of ‘pending’, ‘running’, ‘success’, ‘failed’.
default_title
= param.String(allow_refs=False, default=’’, label=’Default title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018e010>)The default title to display if the other title params are unset.
failed_title
= param.String(allow_None=True, allow_refs=False, label=’Failed title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018dad0>)Title to display when status is failed.
pending_title
= param.String(allow_None=True, allow_refs=False, label=’Pending title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018e290>)Title to display when status is pending.
running_title
= param.String(allow_None=True, allow_refs=False, label=’Running title’, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x13018dd90>)Title to display when status is running.
status
= param.Selector(allow_refs=False, default=’pending’, label=’Status’, names={}, nested_refs=False, objects=[‘pending’, ‘running’, ‘success’, ‘failed’], rx=<param.reactive.reactive_ops object at 0x13018c790>)- append(obj: Any) None [source]#
Appends an object to the layout.
Arguments#
obj (object): Panel component to add to the layout.
- clear() list[Viewable] [source]#
Clears the objects on this layout.
Returns#
objects (list[Viewable]): List of cleared objects.
- clone(*objects: Any, **params: Any) ListLike [source]#
Makes a copy of the layout sharing the same parameters.
Arguments#
objects: Objects to add to the cloned layout. params: Keyword arguments override the parameters on the clone.
Returns#
Cloned layout object
- controls(parameters: list[str] = [], jslink: bool = True, **kwargs) BasePanel [source]#
Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.
Arguments#
- parameters: list(str)
An explicit list of parameters to return controls for.
- jslink: bool
Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.
- kwargs: dict
Additional kwargs to pass to the Param pane(s) used to generate the controls widgets.
Returns#
A layout of the controls
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [source]#
Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.
Arguments#
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for JSON filename
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=False)
Whether to report progress
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- extend(objects: Iterable[Any]) None [source]#
Extends the objects on this layout with a list.
Arguments#
objects (list): List of panel components to add to the layout.
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- index(object) int [source]#
Returns the integer index of the supplied object in the list of objects.
Arguments#
obj (object): Panel component to look up the index for.
Returns#
index (int): Integer index of the object in the layout.
- insert(index: int, obj: Any) None [source]#
Inserts an object in the layout at the specified index.
Arguments#
index (int): Index at which to insert the object. object (object): Panel components to insert in the layout.
- jscallback(args: dict[str, Any] = {}, **callbacks: str) Callback [source]#
Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.
Arguments#
- args: dict
A mapping of objects to make available to the JS callback
- callbacks: dict
A mapping between properties on the source model and the code to execute when that property changes
Returns#
- callback: Callback
The Callback which can be used to disable the callback.
- jslink(target: JSLinkTarget, code: dict[str, str] = None, args: dict | None = None, bidirectional: bool = False, **links: str) Link [source]#
Links properties on the this Reactive object to those on the target Reactive object in JS code.
Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.
Arguments#
- target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
The target to link the value to.
- code: dict
Custom code which will be executed when the widget value changes.
- args: dict
A mapping of objects to make available to the JS callback
- bidirectional: boolean
Whether to link source and target bi-directionally
- links: dict
A mapping between properties on the source model and the target model property to link it to.
Returns#
- link: GenericLink
The GenericLink which can be used unlink the widget and the target model.
- link(target: Parameterized, callbacks: dict[str, str | Callable] | None = None, bidirectional: bool = False, **links: str) Watcher [source]#
Links the parameters on this Reactive object to attributes on the target Parameterized object.
Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.
Arguments#
- target: param.Parameterized
The target object of the link.
- callbacks: dict | None
Maps from a parameter in the source object to a callback.
- bidirectional: bool
Whether to link source and target bi-directionally
- links: dict
Maps between parameters on this object to the parameters on the supplied object.
- pop(index: int) Viewable [source]#
Pops an item from the layout by index.
Arguments#
index (int): The index of the item to pop from the layout.
- remove(obj: Viewable) None [source]#
Removes an object from the layout.
Arguments#
obj (object): The object to remove from the layout.
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str or file-like object
Filename to save the plot to
- title: string
Optional title for the plot
- resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
- template:
passed to underlying io.save
- template_variables:
passed to underlying io.save
- embed: bool
Whether the state space should be embedded in the saved file.
- max_states: int
The maximum number of states to embed
- max_opts: int
The maximum number of states for a single widget
- embed_json: boolean (default=True)
Whether to export the data to json files
- json_prefix: str (default=’’)
Prefix for the auto-generated json directory
- save_path: str (default=’./’)
The path to save json files to
- load_path: str (default=None)
The path or URL the json files will be loaded from.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- selector: type or callable or None
The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.
Returns#
viewables: list(Viewable)
- serialize(prefix_with_viewable_label: bool = True, prefix_with_container_label: bool = True) str [source]#
Format the object to a string.
Arguments#
- prefix_with_viewable_labelbool
Whether to include the name of the Viewable, or type of the viewable if no name is specified.
- prefix_with_container_labelbool
Whether to include the name of the container, or type of the container if no name is specified.
Returns#
- str
The serialized string.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- port: int (optional, default=0)
Allows specifying a specific port
- addressstr
The address the server should listen on for HTTP requests.
- websocket_origin: str or list(str) (optional)
A list of hosts that can connect to the websocket. This is typically required when embedding a server app in an external web site. If None, “localhost” is used.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- stream(token: str | None, replace: bool = False)[source]#
Stream a token to the last available string-like object.
Arguments#
- tokenstr
The token to stream.
- replacebool
Whether to replace the existing text.
Returns#
- Viewable
The updated message pane.
- stream_title(token: str, status: Literal['pending', 'running', 'success', 'failed', 'default'] = 'running', replace: bool = False)[source]#
Stream a token to the title header.
Arguments:#
- tokenstr
The token to stream.
- statusstr
The status title to stream to, one of ‘pending’, ‘running’, ‘success’, ‘failed’, or “default”.
- replacebool
Whether to replace the existing text.
utils
Module#
- panel.chat.utils.avatar_lookup(user: str, avatar: Any, avatars: dict[str, Any], default_avatars: dict[str, Any]) str | BytesIO | bytes | ImageBase [source]#
Lookup the avatar for the user.
- panel.chat.utils.get_obj_label(obj)[source]#
Get the label for the object; defaults to specified object name; if unspecified, defaults to the type name.
- panel.chat.utils.serialize_recursively(obj: Any, prefix_with_viewable_label: bool = True, prefix_with_container_label: bool = True) str [source]#
Recursively serialize the object to a string.
- panel.chat.utils.stream_to(obj, token, replace=False, object_panel=None)[source]#
Updates the message with the new token traversing the object to allow updating nested objects. When traversing a nested Panel the last object that supports rendering strings is updated, e.g. in a layout of Column(Markdown(…), Image(…)) the Markdown pane is updated.
Arguments#
- token: str
The token to stream to the text pane.
- replace: bool (default=False)
Whether to replace the existing text.
- panel.chat.utils.to_alpha_numeric(user: str) str [source]#
Convert the user name to an alpha numeric string, removing all non-alphanumeric characters.