Skip to content

Commit 3d1108c

Browse files
authored
Markdown stream fixes (#1838)
1 parent a781305 commit 3d1108c

File tree

8 files changed

+19
-16
lines changed

8 files changed

+19
-16
lines changed

js/chat/chat.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ class ChatMessage extends LightElement {
6767
<div class="message-icon">${unsafeHTML(icon)}</div>
6868
<shiny-markdown-stream
6969
content=${this.content}
70-
content_type=${this.content_type}
70+
content-type=${this.content_type}
7171
?streaming=${this.streaming}
72+
auto-scroll
7273
></shiny-markdown-stream>
7374
`;
7475
}
@@ -81,7 +82,7 @@ class ChatUserMessage extends LightElement {
8182
return html`
8283
<shiny-markdown-stream
8384
content=${this.content}
84-
content_type="semi-markdown"
85+
content-type="semi-markdown"
8586
></shiny-markdown-stream>
8687
`;
8788
}

shiny/api-examples/MarkdownStream/app-core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
app_ui = ui.page_fluid(
88
ui.card(
99
ui.card_header("Shiny's README.md"),
10-
ui.output_markdown_stream("shiny-readme"),
10+
ui.output_markdown_stream("shiny_readme"),
1111
height="400px",
1212
class_="mt-3",
1313
full_screen=True,
@@ -28,7 +28,7 @@ async def chunk_generator():
2828
await asyncio.sleep(0.02)
2929
yield chunk + " "
3030

31-
md = ui.MarkdownStream("shiny-readme")
31+
md = ui.MarkdownStream("shiny_readme")
3232

3333
@reactive.effect
3434
async def _():

shiny/api-examples/MarkdownStream/app-express.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ui.page_opts(full_width=True)
99

1010
# Initialize a markdown stream object
11-
md = ui.MarkdownStream("shiny-readme")
11+
md = ui.MarkdownStream("shiny_readme")
1212

1313
# Display the stream UI in a card
1414
with ui.card(height="400px", class_="mt-3", full_screen=True):

shiny/ui/_markdown_stream.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from .. import _utils, reactive
77
from .._docstring import add_example
8+
from .._namespaces import resolve_id
89
from .._typing_extensions import TypedDict
910
from ..session import require_active_session
1011
from ..types import NotifyException
@@ -71,7 +72,7 @@ def __init__(
7172
*,
7273
on_error: Literal["auto", "actual", "sanitize", "unhandled"] = "auto",
7374
):
74-
self.id = id
75+
self.id = resolve_id(id)
7576
# TODO: remove the `None` when this PR lands:
7677
# https://github.com/posit-dev/py-shiny/pull/793/files
7778
self._session = require_active_session(None)
@@ -282,6 +283,6 @@ def output_markdown_stream(
282283
"content-type": content_type,
283284
"auto-scroll": "" if auto_scroll else None,
284285
},
285-
id=id,
286+
id=resolve_id(id),
286287
content=content,
287288
)

shiny/www/py-shiny/chat/chat.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/chat/chat.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/playwright/shiny/components/MarkdownStream/basic/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
readme_chunks = f.read().replace("\n", " \n ").split(" ")
1111

1212

13-
stream = ui.MarkdownStream("shiny-readme")
14-
stream_err = ui.MarkdownStream("shiny-readme-err")
13+
stream = ui.MarkdownStream("shiny_readme")
14+
stream_err = ui.MarkdownStream("shiny_readme_err")
1515

1616

1717
async def readme_generator():
@@ -46,7 +46,7 @@ async def _():
4646
stream_err.ui()
4747

4848

49-
basic_stream = ui.MarkdownStream("basic-stream-result")
49+
basic_stream = ui.MarkdownStream("basic_stream_result")
5050
basic_stream.ui()
5151

5252

tests/playwright/shiny/components/MarkdownStream/basic/test_stream_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def is_element_scrolled_to_bottom(page: Page, selector: str) -> bool:
2828
def test_validate_stream_basic(page: Page, local_app: ShinyAppProc) -> None:
2929
page.goto(local_app.url)
3030

31-
stream = page.locator("#shiny-readme")
31+
stream = page.locator("#shiny_readme")
3232
expect(stream).to_be_visible(timeout=30 * 1000)
3333
expect(stream).to_contain_text("pip install shiny")
3434

@@ -37,7 +37,7 @@ def test_validate_stream_basic(page: Page, local_app: ShinyAppProc) -> None:
3737
is_scrolled = is_element_scrolled_to_bottom(page, ".card-body")
3838
assert is_scrolled, "The card body container should be scrolled to the bottom"
3939

40-
stream2 = page.locator("#shiny-readme-err")
40+
stream2 = page.locator("#shiny_readme_err")
4141
expect(stream2).to_be_visible(timeout=30 * 1000)
4242
expect(stream2).to_contain_text("Shiny")
4343

0 commit comments

Comments
 (0)