Skip to content

Commit 95f271a

Browse files
committed
Remove the .ui() entirely from shiny.ui.MarkdownStream
1 parent 2496cc0 commit 95f271a

File tree

2 files changed

+56
-52
lines changed

2 files changed

+56
-52
lines changed

shiny/express/ui/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
insert_ui,
102102
remove_ui,
103103
markdown,
104-
MarkdownStream,
105104
modal_button,
106105
modal,
107106
modal_show,
@@ -147,6 +146,10 @@
147146
popover,
148147
)
149148

149+
from ...ui._markdown_stream import (
150+
ExpressMarkdownStream as MarkdownStream,
151+
)
152+
150153
from ._page import (
151154
page_opts,
152155
)

shiny/ui/_markdown_stream.py

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
__all__ = (
1616
"output_markdown_stream",
1717
"MarkdownStream",
18+
"ExpressMarkdownStream",
1819
)
1920

2021
StreamingContentType = Literal[
@@ -36,7 +37,7 @@ class isStreamingMessage(TypedDict):
3637
isStreaming: bool
3738

3839

39-
@add_example()
40+
@add_example("app-core.py")
4041
class MarkdownStream:
4142
"""
4243
A component for streaming markdown or HTML content.
@@ -84,53 +85,6 @@ def __init__(
8485

8586
self.on_error = on_error
8687

87-
def ui(
88-
self,
89-
*,
90-
content: str = "",
91-
content_type: StreamingContentType = "markdown",
92-
auto_scroll: bool = True,
93-
width: CssUnit = "100%",
94-
height: CssUnit = "auto",
95-
) -> Tag:
96-
"""
97-
Create a UI element for this `MarkdownStream`.
98-
99-
This method is only relevant for Shiny Express. In Shiny Core, use
100-
:func:`~shiny.ui.output_markdown_stream` to create the UI element.
101-
102-
Parameters
103-
----------
104-
content
105-
Content to display when the UI element is first rendered.
106-
content_type
107-
The content type. Default is `"markdown"` (specifically, CommonMark).
108-
Other supported options are:
109-
- `"html"`: for rendering HTML content.
110-
- `"text"`: for plain text.
111-
- `"semi-markdown"`: for rendering markdown, but with HTML tags escaped.
112-
auto_scroll
113-
Whether to automatically scroll to the bottom of a scrollable container
114-
when new content is added. Default is `True`.
115-
width
116-
The width of the UI element.
117-
height
118-
The height of the UI element.
119-
120-
Returns
121-
-------
122-
Tag
123-
A UI element for locating the `MarkdownStream` in the app.
124-
"""
125-
return output_markdown_stream(
126-
self.id,
127-
content=content,
128-
content_type=content_type,
129-
auto_scroll=auto_scroll,
130-
width=width,
131-
height=height,
132-
)
133-
13488
async def stream(
13589
self,
13690
content: Union[Iterable[str], AsyncIterable[str]],
@@ -233,7 +187,54 @@ async def _raise_exception(self, e: BaseException):
233187
raise NotifyException(msg, sanitize=sanitize) from e
234188

235189

236-
@add_example()
190+
@add_example("app-express.py")
191+
class ExpressMarkdownStream(MarkdownStream):
192+
def ui(
193+
self,
194+
*,
195+
content: str = "",
196+
content_type: StreamingContentType = "markdown",
197+
auto_scroll: bool = True,
198+
width: CssUnit = "100%",
199+
height: CssUnit = "auto",
200+
) -> Tag:
201+
"""
202+
Create a UI element for this `MarkdownStream`.
203+
204+
Parameters
205+
----------
206+
content
207+
Content to display when the UI element is first rendered.
208+
content_type
209+
The content type. Default is `"markdown"` (specifically, CommonMark).
210+
Other supported options are:
211+
- `"html"`: for rendering HTML content.
212+
- `"text"`: for plain text.
213+
- `"semi-markdown"`: for rendering markdown, but with HTML tags escaped.
214+
auto_scroll
215+
Whether to automatically scroll to the bottom of a scrollable container
216+
when new content is added. Default is `True`.
217+
width
218+
The width of the UI element.
219+
height
220+
The height of the UI element.
221+
222+
Returns
223+
-------
224+
Tag
225+
A UI element for locating the `MarkdownStream` in the app.
226+
"""
227+
return output_markdown_stream(
228+
self.id,
229+
content=content,
230+
content_type=content_type,
231+
auto_scroll=auto_scroll,
232+
width=width,
233+
height=height,
234+
)
235+
236+
237+
@add_example("app-core.py")
237238
def output_markdown_stream(
238239
id: str,
239240
*,
@@ -246,8 +247,8 @@ def output_markdown_stream(
246247
"""
247248
Create a UI element for a :class:`~shiny.ui.MarkdownStream`.
248249
249-
This method is only relevant for Shiny Core. In Shiny Express, use
250-
:meth:`~shiny.ui.MarkdownStream.ui` to create the UI element.
250+
This function is only relevant for Shiny Core. In Shiny Express, use
251+
:meth:`~shiny.express.ui.MarkdownStream.ui` to create the UI element.
251252
252253
Parameters
253254
----------

0 commit comments

Comments
 (0)