chat_ui
chat_ui(
id,
*,
messages=None,
greeting=None,
placeholder='Enter a message...',
width='min(680px, 100%)',
height='auto',
fill=True,
icon_assistant=None,
enable_cancel=MISSING,
submit_key='enter',
allow_attachments=MISSING,
footer=None,
**kwargs,
)UI container for a chat component (Shiny Core).
This function is for locating a :class:~shiny.ui.Chat instance in a Shiny Core app. If you are using Shiny Express, use the :method:~shiny.ui.Chat.ui method instead.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| id | str | A unique identifier for the chat UI. | required |
| messages | Optional[Iterable[str | TagChild | ChatMessageDict | ChatMessage | Any]] | A sequence of messages to display in the chat. A given message can be one of the following: * A string, which is interpreted as markdown and rendered to HTML on the client. * To prevent interpreting as markdown, mark the string as :class:~shiny.ui.HTML. * A UI element (specifically, a :class:~shiny.ui.TagChild). * This includes :class:~shiny.ui.TagList, which take UI elements (including strings) as children. In this case, strings are still interpreted as markdown as long as they’re not inside HTML. * A dictionary with content and role keys. The content key can contain a content as described above, and the role key can be “assistant” or “user”. * More generally, any type registered with :func:shinychat.message_content. NOTE: content may include specially formatted input suggestion links (see :method:~shiny.ui.Chat.append_message for more info). |
None |
| greeting | Optional[Union[str, HTML, Tag, TagList, ChatGreeting]] | An optional greeting to display at the top of the chat before any conversation messages. Can be a markdown string or a :func:~shinychat.chat_greeting object. For a dynamic or streaming greeting, use :meth:~shinychat.Chat.set_greeting from the server instead. When no greeting is set and the chat is visible with no messages, an input named {id}_greeting_requested fires. Use this input with @reactive.event(input.{id}_greeting_requested) to generate a greeting on demand from the server. It fires again after :meth:~shinychat.Chat.clear_messages is called with greeting=True. |
None |
| placeholder | str | Placeholder text for the chat input. | 'Enter a message...' |
| width | 'CssUnit' | The width of the chat container. | 'min(680px, 100%)' |
| height | 'CssUnit' | The height of the chat container. | 'auto' |
| fill | bool | Whether the chat should vertically take available space inside a fillable container. | True |
| icon_assistant | Optional[HTML | Tag | TagList] | The icon to use for the assistant chat messages. Can be a HTML or a tag in the form of :class:~htmltools.HTML or :class:~htmltools.Tag. If None, a default robot icon is used. |
None |
| enable_cancel | 'bool | MISSING_TYPE' | Whether to show a stop button during streaming that allows the user to cancel the in-progress response. When True, the chat UI shows a stop button in place of the send button while streaming. You must observe input.<id>_cancel on the server and call ctrl.cancel() on a chatlas StreamController to actually stop the stream. When left unset (the default), a chat driven by a client= enables the stop button automatically; otherwise it stays hidden. Passing an explicit True/False always wins over that automatic behavior. |
MISSING |
| submit_key | 'Literal["enter", "enter+modifier"]' | Controls which key combination submits the chat message: - "enter" (default): Enter submits, Shift+Enter adds a newline. - "enter+modifier": Ctrl+Enter (Cmd+Enter on Mac) submits, plain Enter adds a newline. |
'enter' |
| allow_attachments | 'bool | list[str] | MISSING_TYPE' | Controls the file-attachment affordance (an attach button, plus clipboard paste and drag-and-drop) in the chat input. Pass True to accept all supported types (PNG, JPEG, GIF, WebP, PDF, and common text/code files such as Markdown, plain text, CSV, JSON, and source files), False to disable, or a list of MIME types to restrict what is accepted (each must be one of the supported types). Attachments are delivered to your .on_user_submit() handler’s second argument as a list[Attachment], where each item exposes mime, name, size, and data_url attributes (and forwarded to a client= automatically). When left unset (the default), a chat driven by a client= enables attachments automatically; otherwise it stays hidden. The maximum combined size of all attachments in a single message is controlled globally by the SHINYCHAT_MAX_ATTACHMENT_SIZE environment variable (a raw byte count; defaults to approximately 30 MB). Files that would push the total over this cap are rejected in the browser with a notice. When bookmarking is enabled, prefer bookmark_store="server": attachment data is saved in the bookmark and can exceed URL length limits with bookmark_store="url". |
MISSING |
| footer | Optional[TagChild] | Optional HTML content to display below the chat input. This can be any HTML content (tags, tag lists, or strings). Useful for adding disclaimers, attribution, or other information. The footer text is styled slightly smaller and lighter than body text by default. Customize with CSS properties --shiny-chat-footer-font-size and --shiny-chat-footer-color on the chat container or footer element. |
None |
| kwargs | TagAttrValue | Additional attributes for the chat container element. | {} |