Skip to content

Commit b8dfce0

Browse files
committed
Handle UI elements correctly in output_markdown_stream()
1 parent c066da0 commit b8dfce0

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

shiny/ui/_markdown_stream.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from contextlib import asynccontextmanager
22
from typing import AsyncIterable, Iterable, Literal, Union
33

4-
from htmltools import TagChild, css
4+
from htmltools import TagChild, TagList, css
55

66
from .. import _utils, reactive
77
from .._deprecated import warn_deprecated
@@ -263,7 +263,7 @@ class ExpressMarkdownStream(MarkdownStream):
263263
def ui(
264264
self,
265265
*,
266-
content: str = "",
266+
content: TagChild = "",
267267
content_type: StreamingContentType = "markdown",
268268
auto_scroll: bool = True,
269269
width: CssUnit = "100%",
@@ -275,7 +275,9 @@ def ui(
275275
Parameters
276276
----------
277277
content
278-
Content to display when the UI element is first rendered.
278+
A string of content to display before any streaming occurs. When
279+
`content_type` isn't `"text"`, it may also be UI element(s) such as input
280+
and output bindings.
279281
content_type
280282
The content type. Default is `"markdown"` (specifically, CommonMark).
281283
Other supported options are:
@@ -309,7 +311,7 @@ def ui(
309311
def output_markdown_stream(
310312
id: str,
311313
*,
312-
content: str = "",
314+
content: TagChild = "",
313315
content_type: StreamingContentType = "markdown",
314316
auto_scroll: bool = True,
315317
width: CssUnit = "100%",
@@ -327,7 +329,8 @@ def output_markdown_stream(
327329
A unique identifier for the UI element. This id should match the id of the
328330
:class:`~shiny.ui.MarkdownStream` instance.
329331
content
330-
Some content to display before any streaming occurs.
332+
A string of content to display before any streaming occurs. When `content_type`
333+
isn't `"text"`, it may also be UI element(s) such as input and output bindings.
331334
content_type
332335
The content type. Default is "markdown" (specifically, CommonMark).
333336
Other supported options are:
@@ -342,9 +345,12 @@ def output_markdown_stream(
342345
height
343346
The height of the UI element.
344347
"""
348+
ui = TagList(content).render()
349+
345350
return Tag(
346351
"shiny-markdown-stream",
347352
markdown_stream_dependency(),
353+
ui["dependencies"],
348354
{
349355
"style": css(
350356
width=as_css_unit(width),
@@ -354,5 +360,5 @@ def output_markdown_stream(
354360
"auto-scroll": "" if auto_scroll else None,
355361
},
356362
id=resolve_id(id),
357-
content=content,
363+
content=ui["html"],
358364
)

0 commit comments

Comments
 (0)