ui.MarkdownStream

ui.MarkdownStream(self, id, *, on_error='auto')

A component for streaming markdown or HTML content.

Parameters

id : str

A unique identifier for this MarkdownStream. In Shiny Core, make sure this id matches a corresponding output_markdown_stream call in the app’s UI.

on_error : Literal[‘auto’, ‘actual’, ‘sanitize’, ‘unhandled’] = 'auto'

How to handle errors that occur while streaming. When "unhandled", the app will stop running when an error occurs. Otherwise, a notification is displayed to the user and the app continues to run. * "auto": Sanitize the error message if the app is set to sanitize errors, otherwise display the actual error message. * "actual": Display the actual error message to the user. * "sanitize": Sanitize the error message before displaying it to the user. * "unhandled": Do not display any error message to the user.

Note

Markdown is parsed on the client via marked.js. Consider using markdown for server-side rendering of markdown content.

Examples

Loading...




Attributes

Name Description
latest_stream React to changes in the latest stream.

Methods

Name Description
clear Empty the UI element of the MarkdownStream.
get_latest_stream_result Reactively read the latest stream result.
stream Send a stream of content to the UI.

clear

ui.MarkdownStream.clear()

Empty the UI element of the MarkdownStream.

get_latest_stream_result

ui.MarkdownStream.get_latest_stream_result()

Reactively read the latest stream result.

Deprecated. Use latest_stream.result() instead.

stream

ui.MarkdownStream.stream(content, clear=True)

Send a stream of content to the UI.

Stream content into the relevant UI element.

Parameters

content : Union[Iterable[TagChild], AsyncIterable[TagChild]]

The content to stream. This can be a Iterable or an AsyncIterable of strings. Note that this includes synchronous and asynchronous generators, which is a useful way to stream content in as it arrives (e.g. from a LLM).

clear : bool = True

Whether to clear the existing content before streaming the new content.

Note

If you already have the content available as a string, you can do .stream([content]) to set the content.

Returns

:

An extended task that represents the streaming task. The .result() method of the task can be called in a reactive context to get the final state of the stream.