Skip to content

Commit 59ff081

Browse files
authored
feat(card): Report full screen state as a Shiny input (#1215)
1 parent 446c8ac commit 59ff081

File tree

68 files changed

+1649
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1649
-53
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### New features
1313

14+
* `ui.card()` and `ui.value_box()` now take an `id` argument that, when provided, is used to report the full screen state of the card or value box to the server. For example, when using `ui.card(id = "my_card", full_screen = TRUE)` you can determine if the card is currently in full screen mode by reading the boolean value of `input.my_card()["full_screen"]`. (#1215)
15+
1416
### Bug fixes
1517

1618
### Other changes

scripts/htmlDependencies.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ignore <- capture.output({
2020
pak::pkg_install(c(
2121
"rstudio/bslib@main",
2222
"rstudio/shiny@main",
23+
"rstudio/sass@main",
2324
"cran::htmltools"
2425
))
2526
#pak::pkg_install(c("rstudio/bslib@main", "rstudio/shiny@main", "rstudio/htmltools@main"))

shiny/experimental/ui/_card.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def card(
104104
fill=fill,
105105
class_=class_,
106106
wrapper=wrapper,
107+
id=None,
107108
**kwargs,
108109
)
109110

shiny/experimental/ui/_deprecated.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ def value_box(
11341134
max_height=max_height,
11351135
fill=fill,
11361136
class_=class_,
1137+
id=None,
11371138
**kwargs,
11381139
)
11391140

shiny/ui/_card.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
)
1717

1818
from .._docstring import add_example
19+
from .._namespaces import resolve_id_or_none
1920
from .._utils import private_random_id
2021
from ..types import MISSING, MISSING_TYPE
2122
from ._html_deps_shinyverse import components_dependencies
@@ -54,6 +55,7 @@ def card(
5455
min_height: Optional[CssUnit] = None,
5556
fill: bool = True,
5657
class_: Optional[str] = None,
58+
id: Optional[str] = None,
5759
# wrapper: WrapperCallable | None | MISSING_TYPE = MISSING,
5860
**kwargs: TagAttrValue,
5961
) -> Tag:
@@ -79,6 +81,10 @@ def card(
7981
an opinionated height (e.g., :func:`~shiny.ui.page_fillable`).
8082
class_
8183
Additional CSS classes for the returned Tag.
84+
id
85+
Provide a unique identifier for the :func:`~shiny.ui.card` or to report its
86+
state to Shiny. For example, using `id="my_card"`, you can observe the card's
87+
full screen state with `input.my_card()["full_screen"]`.
8288
**kwargs
8389
HTML attributes on the returned Tag.
8490
@@ -102,6 +108,7 @@ def card(
102108
min_height=min_height,
103109
fill=fill,
104110
class_=class_,
111+
id=id,
105112
wrapper=MISSING,
106113
**kwargs,
107114
)
@@ -115,6 +122,7 @@ def _card_impl(
115122
min_height: Optional[CssUnit] = None,
116123
fill: bool = True,
117124
class_: Optional[str] = None,
125+
id: Optional[str] = None,
118126
wrapper: WrapperCallable | None | MISSING_TYPE = MISSING,
119127
**kwargs: TagAttrValue,
120128
) -> Tag:
@@ -131,11 +139,15 @@ def _card_impl(
131139
attrs, children = consolidate_attrs(*args, class_=class_, **kwargs)
132140
children = _wrap_children_in_card(*children, wrapper=wrapper)
133141

134-
if full_screen and "id" not in attrs:
135-
attrs["id"] = private_random_id("bslib_card")
142+
id = resolve_id_or_none(id)
143+
is_shiny_input = id is not None
144+
145+
if full_screen and id is None:
146+
id = private_random_id("bslib_card")
136147

137148
tag = div(
138149
{
150+
"id": id,
139151
"class": "card bslib-card bslib-mb-spacing",
140152
"style": css(
141153
height=as_css_unit(height),
@@ -145,9 +157,10 @@ def _card_impl(
145157
"data-bslib-card-init": True,
146158
"data-full-screen": "false" if full_screen else None,
147159
},
160+
{"class": "bslib-card-input"} if is_shiny_input else None,
148161
*children,
149162
attrs,
150-
_full_screen_toggle(attrs["id"]) if full_screen else None,
163+
_full_screen_toggle(id) if full_screen else None,
151164
components_dependencies(),
152165
_card_js_init(),
153166
)

shiny/ui/_valuebox.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ def value_box(
309309
max_height: Optional[CssUnit] = None,
310310
fill: bool = True,
311311
class_: Optional[str] = None,
312+
id: Optional[str] = None,
312313
**kwargs: TagAttrValue,
313314
) -> Tag:
314315
"""
@@ -367,6 +368,10 @@ def value_box(
367368
Utility classes for customizing the appearance of the summary card. Use `bg-*`
368369
and `text-*` classes (e.g, `"bg-danger"` and `"text-light"`) to customize the
369370
background/foreground colors.
371+
id
372+
Provide a unique identifier for the :func:`~shiny.ui.value_box()` to report its
373+
state to Shiny. For example, using `id="my_value_box"`, you can observe the
374+
value box's full screen state with `input.my_value_box()["full_screen"]`.
370375
**kwargs
371376
Additional attributes to pass to :func:`~shiny.ui.card`.
372377
@@ -459,6 +464,7 @@ def value_box(
459464
height=height,
460465
max_height=max_height,
461466
fill=fill,
467+
id=id,
462468
)
463469

464470

shiny/www/shared/_version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
33
"package": "shiny",
4-
"version": "Github (rstudio/shiny@6760c318184535185e5050aefe29e658e8710ef0)"
4+
"version": "Github (rstudio/shiny@e2b7f9113866a2f0a98b0cac240320116c5ff56a)"
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
3-
"shiny_version": "Github (rstudio/shiny@6760c318184535185e5050aefe29e658e8710ef0)",
4-
"bslib_version": "Github (rstudio/bslib@1929f7e63197f6073085a03f926f11829b7292ea)",
3+
"shiny_version": "Github (rstudio/shiny@e2b7f9113866a2f0a98b0cac240320116c5ff56a)",
4+
"bslib_version": "Github (rstudio/bslib@8751c7cc1d883f3d04c727e7f0eab89a34f1404c)",
55
"htmltools_version": "CRAN (R 4.3.1)",
66
"bootstrap_version": "5.3.1"
77
}

0 commit comments

Comments
 (0)