Skip to content

Commit

Permalink
Express: don't automatically put strings in a <pre> block (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
wch authored Dec 15, 2023
1 parent dffb874 commit 88deca4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ install_requires =
starlette>=0.17.1
websockets>=10.0
python-multipart
htmltools>=0.4.1.9001
htmltools @ git+https://github.com/posit-dev/py-htmltools.git
click>=8.1.4
markdown-it-py>=1.1.0
# This is needed for markdown-it-py. Without it, when loading shiny/ui/_markdown.py,
Expand Down
17 changes: 2 additions & 15 deletions shiny/express/_recall_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from types import TracebackType
from typing import Callable, Generic, Mapping, Optional, Type, TypeVar

from htmltools import HTML, Tag, Tagifiable, TagList, tags
from htmltools import Tag, wrap_displayhook_handler

from .._typing_extensions import ParamSpec

Expand All @@ -32,19 +32,6 @@ def __init__(
self.args: list[object] = list(args)
self.kwargs: dict[str, object] = dict(kwargs)

def append_arg(self, value: object):
if isinstance(value, (Tag, TagList, Tagifiable)):
self.args.append(value)
elif hasattr(value, "_repr_html_"):
self.args.append(HTML(value._repr_html_())) # pyright: ignore
else:
# We should NOT end up here for objects that were `def`ed, because they
# would already have been filtered out by _display_decorator_function_def().
# This is only for other kinds of expressions, the kind which would normally
# be printed at the console.
if value is not None:
self.args.append(tags.pre(repr(value)))

def __enter__(self) -> None:
if self.default_page is not None:
from . import _run
Expand All @@ -53,7 +40,7 @@ def __enter__(self) -> None:

self._prev_displayhook = sys.displayhook
# Collect each of the "printed" values in the args list.
sys.displayhook = self.append_arg
sys.displayhook = wrap_displayhook_handler(self.args.append)

def __exit__(
self,
Expand Down
4 changes: 2 additions & 2 deletions shiny/render/_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from typing import Any, Callable, Optional, Union, overload

from htmltools import TagAttrValue, TagFunction, TagList
from htmltools import TagAttrValue, TagFunction, TagList, wrap_displayhook_handler

from .. import ui as _ui
from ..session._utils import RenderedDeps
Expand All @@ -29,7 +29,7 @@ async def DisplayTransformer(
) -> RenderedDeps | None:
results: list[object] = []
orig_displayhook = sys.displayhook
sys.displayhook = results.append
sys.displayhook = wrap_displayhook_handler(results.append)
try:
x = _fn()
if inspect.iscoroutine(x):
Expand Down
6 changes: 3 additions & 3 deletions tests/playwright/utils/express_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def verify_express_page_default(page: Page) -> None:
nav_html.set("span")
nav_html.expect_content("span 0span 1span 2")
navset_card_tab = LayoutNavsetTab(page, "express_navset_card_tab")
navset_card_tab.expect_content("Ellipsis")
navset_card_tab.expect_content("")
# since it is a custom table we can't use the OutputTable controls
shell_text = page.locator("#shell").inner_text().strip()
assert shell_text == (
"'R1C1R1'\n'R1C1R2-R1C1R1'\n'R1C1R2-R1C1R2'\n'R1C1R2-R1C2'\n'R1C2'"
"R1C1R1\nR1C1R2-R1C1R1\nR1C1R2-R1C1R2\nR1C1R2-R1C2\nR1C2"
), "Locator contents don't match expected text"


Expand All @@ -79,7 +79,7 @@ def verify_express_page_fluid(page: Page) -> None:

def verify_express_page_sidebar(page: Page) -> None:
sidebar = Sidebar(page, "sidebar")
sidebar.expect_text("SidebarTitle 'Sidebar Content'")
sidebar.expect_text("SidebarTitle Sidebar Content")
output_txt = OutputTextVerbatim(page, "txt")
output_txt.expect_value("50")
compare_annotations(ui.sidebar, layout.sidebar)

0 comments on commit 88deca4

Please sign in to comment.