ui.output_markdown_stream

ui.output_markdown_stream(
    id,
    *,
    content='',
    content_type='markdown',
    auto_scroll=True,
    width='100%',
    height='auto',
)

Create a UI element for a MarkdownStream.

This function is only relevant for Shiny Core. In Shiny Express, use ui to create the UI element.

Parameters

id : str

A unique identifier for the UI element. This id should match the id of the MarkdownStream instance.

content : str = ''

Some content to display before any streaming occurs.

content_type : StreamingContentType = 'markdown'

The content type. Default is “markdown” (specifically, CommonMark). Other supported options are: - "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 = '100%'

The width of the UI element.

height : CssUnit = 'auto'

The height of the UI element.

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
import asyncio

import requests

from shiny import App, reactive, ui

app_ui = ui.page_fluid(
    ui.card(
        ui.card_header("Shiny's README.md"),
        ui.output_markdown_stream("shiny_readme"),
        height="400px",
        class_="mt-3",
        full_screen=True,
    ),
)


def server(input, output, session):
    # 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:
            await asyncio.sleep(0.02)
            yield chunk + " "

    md = ui.MarkdownStream("shiny_readme")

    @reactive.effect
    async def _():
        await md.stream(chunk_generator())


app = App(app_ui, server)