Skip to content

Commit e46d600

Browse files
committed
Updated tests and doc strings
1 parent 5be9d98 commit e46d600

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

shiny/ui/_input_date.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def input_date(
4545
value
4646
The starting date. Either a :class:`~datetime.date` object, or a string in
4747
`yyyy-mm-dd` format. If None (the default), will use the current date in the
48-
client's time zone.
48+
client's time zone. If an empty string is passed, the date picker will be blank.
4949
min
5050
The minimum allowed date. Either a :class:`~datetime.date` object, or a string in
5151
yyyy-mm-dd format.

shiny/ui/_input_update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ def update_date(
464464
An input label.
465465
value
466466
The starting date. Either a `date()` object, or a string in yyyy-mm-dd format.
467-
If ``None`` (the default), will use the current date in the client's time zone.
468467
min
469468
The minimum allowed value.
470469
max
@@ -475,14 +474,15 @@ def update_date(
475474
476475
Note
477476
----
478-
{note}
477+
You cannot update the value of a date input to `None` or an empty string.
479478
480479
See Also
481480
--------
482481
* :func:`~shiny.ui.input_date`
483482
"""
484483

485484
session = require_active_session(session)
485+
486486
msg = {
487487
"label": session._process_ui(label) if label is not None else None,
488488
"value": _as_date_attr(value),

tests/playwright/shiny/components/datepicker/app.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
from datetime import datetime
1+
from datetime import date
22

33
from dateutil.relativedelta import relativedelta
44

5-
from shiny import App, Inputs, Outputs, Session, render, ui
5+
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
66

7-
min_date = datetime.fromisoformat("2011-11-04T00:05:23")
7+
min_date = date.fromisoformat("2011-11-04")
88
max_date = min_date + relativedelta(days=10)
99

1010
# Our input requires strings to be in the format "YYYY-MM-DD"
1111
str_min = min_date.strftime("%Y-%m-%d")
1212
str_max = max_date.strftime("%Y-%m-%d")
1313

14-
ui = ui.page_fluid(
14+
app_ui = ui.page_fluid(
1515
ui.input_date(
1616
"start_date_picker",
1717
"Date Type Input:",
@@ -42,15 +42,7 @@
4242
language="en",
4343
),
4444
ui.output_text("str_format"),
45-
ui.input_date(
46-
"none_date_picker",
47-
"None Type Input:",
48-
value=None,
49-
min=None,
50-
max=None,
51-
format="yyyy-mm-dd",
52-
language="en",
53-
),
45+
ui.input_date("none_date_picker", "None Type Input:"),
5446
ui.output_text("none_format"),
5547
ui.input_date(
5648
"empty_date_picker",
@@ -62,6 +54,7 @@
6254
language="en",
6355
),
6456
ui.output_text("empty_format"),
57+
ui.input_action_button("update", "Update Dates"),
6558
)
6659

6760

@@ -86,5 +79,15 @@ def none_format():
8679
def empty_format():
8780
return "Date Picker Value: " + str(input.empty_date_picker())
8881

82+
@reactive.effect
83+
@reactive.event(input.update, ignore_none=True, ignore_init=True)
84+
def _():
85+
d = date.fromisoformat("2011-11-05")
86+
ui.update_date("start_date_picker", value=d)
87+
ui.update_date("str_date_picker", value="2020-01-01")
88+
89+
# Note: You cannot update the value of a date input to None (it will be dropped).
90+
# Note: You cannot update the value of a date input to an empty string. This is a Bootstrap Datepicker limitation.
91+
8992

90-
app = App(ui, server, debug=True)
93+
app = App(app_ui, server, debug=True)

tests/playwright/shiny/components/datepicker/test_datepicker.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from playwright.sync_api import Page, expect
1+
import datetime
2+
3+
from playwright.sync_api import Page
24

35
from shiny.playwright import controller
46
from shiny.run import ShinyAppProc
5-
import datetime
67

78

89
def test_dynamic_navs(page: Page, local_app: ShinyAppProc) -> None:
@@ -48,3 +49,11 @@ def test_dynamic_navs(page: Page, local_app: ShinyAppProc) -> None:
4849

4950
date_output5 = controller.OutputText(page, "empty_format")
5051
date_output5.expect_value("Date Picker Value: None")
52+
53+
controller.InputActionButton(page, "update").click()
54+
55+
date1.expect_value("05.11.2011")
56+
date_output.expect_value("Date Picker Value: 2011-11-05")
57+
58+
date3.expect_value("01-01-2020")
59+
date_output3.expect_value("Date Picker Value: 2020-01-01")

0 commit comments

Comments
 (0)