Skip to content

Commit 2fbc800

Browse files
authored
feat(data frame styles): Allow style "location" to not be required (posit-dev#1548)
1 parent 798d02c commit 2fbc800

File tree

10 files changed

+25
-24
lines changed

10 files changed

+25
-24
lines changed

.github/py-shiny/setup/action.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ runs:
2121
shell: bash
2222
run: python -m pip install --upgrade pip
2323

24+
- name: Pip list
25+
shell: bash
26+
run: |
27+
pip list
28+
2429
- name: Install dependencies
2530
shell: bash
2631
run: |
@@ -31,3 +36,14 @@ runs:
3136
shell: bash
3237
run: |
3338
make install
39+
40+
- name: Install backports.tarfile
41+
if: ${{ startsWith(inputs.python-version, '3.8') }}
42+
shell: bash
43+
run: |
44+
pip install backports.tarfile
45+
46+
- name: Pip list
47+
shell: bash
48+
run: |
49+
pip list

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
green_styles = [
66
{
7-
"location": "body",
87
"rows": [2, 4],
98
"cols": [2, 4],
109
"style": {
@@ -28,7 +27,6 @@
2827

2928
hi_styles = [
3029
{
31-
"location": "body",
3230
# No `rows` or `cols` means apply to all cells
3331
"class": "posit-bg",
3432
"style": {
@@ -37,7 +35,6 @@
3735
},
3836
},
3937
{
40-
"location": "body",
4138
"rows": [3],
4239
"cols": [2],
4340
"class": "posit-blue-bg",
@@ -47,12 +44,10 @@
4744
},
4845
},
4946
{
50-
"location": "body",
5147
"cols": [1, 3, 5],
5248
"class": "posit-blue-bg",
5349
},
5450
{
55-
"location": "body",
5651
"cols": [7],
5752
"rows": [0, 1, 2, 3, 5],
5853
"class": "posit-orange-bg",

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
green_styles = [
66
{
7-
"location": "body",
87
"rows": [2, 4],
98
"cols": [2, 4],
109
"style": {
@@ -59,7 +58,6 @@ def my_df():
5958

6059
hi_styles = [
6160
{
62-
"location": "body",
6361
# No `rows` or `cols` means apply to all cells
6462
"class": "posit-bg",
6563
"style": {
@@ -68,7 +66,6 @@ def my_df():
6866
},
6967
},
7068
{
71-
"location": "body",
7269
"rows": [3],
7370
"cols": [2],
7471
"class": "posit-blue-bg",
@@ -78,12 +75,10 @@ def my_df():
7875
},
7976
},
8077
{
81-
"location": "body",
8278
"cols": [1, 3, 5],
8379
"class": "posit-blue-bg",
8480
},
8581
{
86-
"location": "body",
8782
"cols": [7],
8883
"rows": [0, 1, 2, 3, 5],
8984
"class": "posit-orange-bg",

shiny/render/_data_frame_utils/_datagridtable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DataGrid(AbstractTabularData, Generic[DataFrameLikeT]):
8484
`styles=None`, no styling will be applied.
8585
8686
Style info object key/value description:
87-
* `location`: This value is required and currently only supports `"body"`.
87+
* `location`: This value `"body"` and is not required.
8888
* `rows`: The row numbers to which the style should be applied. If `None`, the
8989
style will be applied to all rows.
9090
* `cols`: The column numbers to which the style should be applied. If `None`,
@@ -243,7 +243,7 @@ class DataTable(AbstractTabularData, Generic[DataFrameLikeT]):
243243
`styles=None`, no styling will be applied.
244244
245245
Style info object key/value description:
246-
* `location`: This value is required and currently only supports `"body"`.
246+
* `location`: This value `"body"` and is not required.
247247
* `rows`: The row numbers to which the style should be applied. If `None`, the
248248
style will be applied to all rows.
249249
* `cols`: The column numbers to which the style should be applied. If `None`,

shiny/render/_data_frame_utils/_styles.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ def style_info_to_browser_style_info(
1919
raise TypeError("`StyleInfo` objects must be a dictionary. Received: ", info)
2020

2121
location = info.get("location", None)
22+
if location is None:
23+
location = "body"
24+
2225
if location != "body":
23-
raise ValueError(f"Unsupported `StyleInfo` location: {location}")
26+
raise ValueError(
27+
f"`StyleInfo` `location` value must be 'body', not '{location}'"
28+
)
2429

2530
rows = style_info_rows(info, nrow=nrow)
2631
cols = style_info_cols(info, browser_column_names=browser_column_names)

shiny/render/_data_frame_utils/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class FrameDtypeCategories(TypedDict):
208208
StyleInfoBody = TypedDict(
209209
"StyleInfoBody",
210210
{
211-
"location": Required[Literal["body"]],
211+
"location": NotRequired[Literal["body"]],
212212
"rows": NotRequired[Union[int, ListOrTuple[int], ListOrTuple[bool], None]],
213213
"cols": NotRequired[
214214
Union[str, int, ListOrTuple[str], ListOrTuple[int], ListOrTuple[bool], None]

tests/playwright/shiny/components/data_frame/styles/app.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,14 @@
5151

5252
df_styles: list[render.StyleInfo] = [
5353
{
54-
"location": "body",
5554
"style": {"color": "darkorange", "font-weight": "bold"},
5655
},
5756
{
58-
"location": "body",
5957
"rows": None,
6058
"cols": None,
6159
"style": {"background-color": "lightblue"},
6260
},
6361
{
64-
"location": "body",
6562
"rows": [1, 2],
6663
"cols": "Species",
6764
"style": {

tests/playwright/shiny/components/data_frame/styles/test_df_styles.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def test_validate_column_labels(
2222

2323
styles: list[dict[str, Jsonifiable]] = [
2424
{
25-
"location": "body",
2625
"rows": [1, 2],
2726
"cols": [2], # "Species",
2827
"style": {
@@ -32,19 +31,16 @@ def test_validate_column_labels(
3231
},
3332
},
3433
{
35-
"location": "body",
3634
"rows": [2],
3735
"cols": [3], # "Region",
3836
"style": {"background-color": "yellow"},
3937
},
4038
{
41-
"location": "body",
4239
"rows": None,
4340
"cols": [4], # "Island",
4441
"style": {"background-color": "red"},
4542
},
4643
{
47-
"location": "body",
4844
"rows": [1],
4945
"cols": [4, 5], # "Island", "Stage",
5046
"style": {"background-color": "green"},

tests/playwright/shiny/components/data_frame/styles_class/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
df_styles: list[StyleInfo] = [
1919
{
20-
"location": "body",
2120
"class": "everywhere",
2221
},
2322
{

tests/playwright/shiny/components/data_frame/styles_class/test_df_styles_class.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ def test_validate_column_labels(page: Page, local_app: ShinyAppProc) -> None:
1616

1717
styles: list[dict[str, Jsonifiable]] = [
1818
{
19-
"location": "body",
2019
"style": {"color": "darkorange", "font-weight": "bold"},
2120
"class": "everywhere",
2221
},
2322
{
24-
"location": "body",
2523
"rows": [1, 2],
2624
"cols": [2], # "Species",
2725
"class": "species",

0 commit comments

Comments
 (0)