Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion shiny/ui/_markdown_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ async def _task():

_task()

self._latest_stream.set(_task)

# Since the task runs in the background (outside/beyond the current context,
# if any), we need to manually raise any exceptions that occur
@reactive.effect
Expand Down Expand Up @@ -208,7 +210,7 @@ def get_latest_stream_result(self) -> Union[str, None]:
"The `.get_latest_stream_result()` method is deprecated and will be removed "
"in a future release. Use `.latest_stream.result()` instead. "
)
self.latest_stream.result()
return self.latest_stream.result()

async def clear(self):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import asyncio

from shiny import reactive
from shiny.express import input, render, ui

stream = ui.MarkdownStream("stream_id")
stream.ui()


ui.input_action_button("do_stream", "Do stream")


async def gen():
yield "Hello "
await asyncio.sleep(0.1)
yield "world!"


@reactive.effect
@reactive.event(input.do_stream)
async def _():
await stream.stream(gen())


@render.code
def stream_result():
res = stream.latest_stream.result()
return f"Stream result: {res}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from playwright.sync_api import Page, expect

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_latest_stream_result(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

stream = page.locator("#stream_id")
stream_result = controller.OutputCode(page, "stream_result")
stream_result.expect_value("")

btn = controller.InputActionButton(page, "do_stream")
btn.click()

expect(stream).to_contain_text("Hello world!")
stream_result.expect_value("Stream result: Hello world!")
Loading