express.ui.MarkdownStream
id, *, on_error='auto') express.ui.MarkdownStream(
Examples
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
## file: app.py
import asyncio
import requests
from shiny import reactive
from shiny.express import session, ui
ui.page_opts(full_width=True)
# Initialize a markdown stream object
md = ui.MarkdownStream("shiny_readme")
# Display the stream UI in a card
with ui.card(height="400px", class_="mt-3", full_screen=True):
ui.card_header("Shiny README.md")
md.ui()
# Read in the README.md file from the py-shiny repository
readme = requests.get(
"https://raw.githubusercontent.com/posit-dev/py-shiny/refs/heads/main/README.md"
)
readme_chunks = readme.text.replace("\n", " \n ").split(" ")
# Generate words from the README.md file (with a small delay)
async def chunk_generator():
for chunk in readme_chunks:
if not session.is_stub_session():
await asyncio.sleep(0.02)
yield chunk + " "
@reactive.effect
async def _():
await md.stream(chunk_generator())
Methods
Name | Description |
---|---|
ui | Create a UI element for this MarkdownStream . |
ui
express.ui.MarkdownStream.ui(='',
content='markdown',
content_type=True,
auto_scroll='min(680px, 100%)',
width='auto',
height )
Create a UI element for this MarkdownStream
.
Parameters
content : TagChild = ''
-
A string of content to display before any streaming occurs. When
content_type
is Markdown or HTML, it may also be UI element(s) such as input and output bindings. content_type :
StreamingContentType
= 'markdown'-
The content type. Default is
"markdown"
(specifically, CommonMark). Supported content types include: -"markdown"
: markdown text, specifically CommonMark -"html"
: for rendering HTML content. -"text"
: for plain text. -"semi-markdown"
: for rendering markdown, but with HTML tags escaped. auto_scroll : bool = True
-
Whether to automatically scroll to the bottom of a scrollable container when new content is added. Default is
True
. width :
CssUnit
= 'min(680px, 100%)'-
The width of the UI element.
height :
CssUnit
= 'auto'-
The height of the UI element.
Returns
: Tag
-
A UI element for locating the
MarkdownStream
in the app.