From 9108a2d3bd5a97791917c91a37c3a8a30fbb63b8 Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Wed, 21 Oct 2026 05:34:04 -0400 Subject: [PATCH 1/6] fix(reactive): don't call an async poll_func without awaiting it in poll() poll() seeded its last value with poll_func(), which for an async poll_func is a coroutine that is never awaited. The polling effect then compared the first real value with that coroutine through equals, so a custom equals raised, the previous value was never replaced, and every later poll failed the same way. Seed an async poll_func with a placeholder and treat the first polled value as changed, without calling equals. --- CHANGELOG.md | 2 ++ shiny/reactive/_poll.py | 12 ++++++++++-- tests/pytest/test_poll.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5658f9c70f..605eb5cee9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes and minor improvements +* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`. Previously `@poll()` called the function without awaiting it and kept the un-awaited coroutine as the "previous value", so a custom `equals` raised on its first comparison and every later poll failed with the same error. + * On Windows, an output's busy indicator now shows while the output renders. Previously, when a synchronous render function blocked the event loop, the message that turns on the indicator reached the browser together with the output's new value, so most outputs never showed it (#1381). * UI updates and custom messages sent outside an output or effect, such as `ui.update_text()` in a `session.on_flushed()` callback or in an `asyncio` task, or `ui.insert_ui()` from a message handler, are now sent to the client right away instead of waiting for the next input change (#1889, #21). diff --git a/shiny/reactive/_poll.py b/shiny/reactive/_poll.py index 0c5d34c598..85ba20195f 100644 --- a/shiny/reactive/_poll.py +++ b/shiny/reactive/_poll.py @@ -16,6 +16,10 @@ T = TypeVar("T") +# Stands in for the first `poll_func` value of an async `poll_func`, which the polling +# effect reads on its first run. +_NO_VALUE: Any = object() + @add_example() def poll( @@ -99,7 +103,11 @@ def poll( with otel.suppress(): with reactive.isolate(): - last_value: reactive.Value[Any] = reactive.Value(poll_func()) + # An async `poll_func` can't be awaited here, so the effect below reads its + # first value instead. + last_value: reactive.Value[Any] = reactive.Value( + _NO_VALUE if _utils.is_async_callable(poll_func) else poll_func() + ) last_error: reactive.Value[Optional[Exception]] = reactive.Value(None) @reactive.effect(priority=priority, session=session) @@ -114,7 +122,7 @@ async def _(): old = last_value.get() try: - is_equal = equals(old, new) + is_equal = False if old is _NO_VALUE else equals(old, new) except Exception as e: # For example, pandas DataFrame throws if you try to compare it to a # non-comparable object diff --git a/tests/pytest/test_poll.py b/tests/pytest/test_poll.py index 69906de88a..f74d3a19ee 100644 --- a/tests/pytest/test_poll.py +++ b/tests/pytest/test_poll.py @@ -145,6 +145,39 @@ def _(): assert (poll_invocations, value_invocations) == (6, 4) +@pytest.mark.asyncio +async def test_poll_async_poll_func_with_custom_equals(): + async with OnEndedSessionCallbacks(): + poll_invocations = 0 + + async def poll_func(): + nonlocal poll_invocations + poll_invocations += 1 + return {"version": 1} + + @poll(poll_func, equals=lambda old, new: old["version"] == new["version"]) + def value_func(): + return "data" + + mock_time = MockTime() + with mock_time(): + # An async poll_func can't be awaited when @poll() runs, so nothing has + # been polled yet and there is no previous value to compare with. + assert poll_invocations == 0 + + await flush() + assert poll_invocations == 1 + + with isolate(): + assert value_func() == "data" + + await mock_time.advance_time(1.01) + assert poll_invocations == 2 + + with isolate(): + assert value_func() == "data" + + @pytest.mark.asyncio async def test_poll_errors(): async with OnEndedSessionCallbacks(): From d454109ab9935349b0d2e748b49874f05acabf8e Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Wed, 21 Oct 2026 05:37:13 -0400 Subject: [PATCH 2/6] docs: add PR number to the changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 605eb5cee9..df8401b14c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes and minor improvements -* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`. Previously `@poll()` called the function without awaiting it and kept the un-awaited coroutine as the "previous value", so a custom `equals` raised on its first comparison and every later poll failed with the same error. +* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`. Previously `@poll()` called the function without awaiting it and kept the un-awaited coroutine as the "previous value", so a custom `equals` raised on its first comparison and every later poll failed with the same error. (#2576) * On Windows, an output's busy indicator now shows while the output renders. Previously, when a synchronous render function blocked the event loop, the message that turns on the indicator reached the browser together with the output's new value, so most outputs never showed it (#1381). From f0119dd7eab82aebb30a43bf87d6a31dedde7b6f Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Wed, 21 Oct 2026 11:03:11 -0400 Subject: [PATCH 3/6] refactor(reactive): seed poll() with a placeholder for sync and async poll_func Review suggestion from cpsievert: one code path, and no reactive.isolate() needed because poll_func is no longer called while seeding. --- CHANGELOG.md | 2 +- shiny/reactive/_poll.py | 11 ++++------- tests/pytest/test_poll.py | 24 ++++++++++++------------ 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df8401b14c..ef003e87af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes and minor improvements -* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`. Previously `@poll()` called the function without awaiting it and kept the un-awaited coroutine as the "previous value", so a custom `equals` raised on its first comparison and every later poll failed with the same error. (#2576) +* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`. Previously `@poll()` called the function without awaiting it and kept the un-awaited coroutine as the "previous value", so a custom `equals` raised on its first comparison and every later poll failed with the same error. `poll_func` is also no longer called once when `@poll()` is applied: the polling effect reads the first value when it first runs. (#2576) * On Windows, an output's busy indicator now shows while the output renders. Previously, when a synchronous render function blocked the event loop, the message that turns on the indicator reached the browser together with the output's new value, so most outputs never showed it (#1381). diff --git a/shiny/reactive/_poll.py b/shiny/reactive/_poll.py index 85ba20195f..1a4663998c 100644 --- a/shiny/reactive/_poll.py +++ b/shiny/reactive/_poll.py @@ -102,13 +102,10 @@ def poll( """ with otel.suppress(): - with reactive.isolate(): - # An async `poll_func` can't be awaited here, so the effect below reads its - # first value instead. - last_value: reactive.Value[Any] = reactive.Value( - _NO_VALUE if _utils.is_async_callable(poll_func) else poll_func() - ) - last_error: reactive.Value[Optional[Exception]] = reactive.Value(None) + # The first value is read by the effect below; calling `poll_func` here would also + # run it outside the polling loop, and an async one can't be awaited. + last_value: reactive.Value[Any] = reactive.Value(_NO_VALUE) + last_error: reactive.Value[Optional[Exception]] = reactive.Value(None) @reactive.effect(priority=priority, session=session) async def _(): diff --git a/tests/pytest/test_poll.py b/tests/pytest/test_poll.py index f74d3a19ee..dab384d2e6 100644 --- a/tests/pytest/test_poll.py +++ b/tests/pytest/test_poll.py @@ -93,56 +93,56 @@ def value_func(): mock_time = MockTime() with mock_time(): - # Poll func is invoked once during @poll(), to seed the underlying reactive val - assert (poll_invocations, value_invocations) == (1, 0) + # Poll func is not invoked during @poll(); the polling observer reads the first value + assert (poll_invocations, value_invocations) == (0, 0) await flush() # The observer that updates poll has executed once. # @poll returns a lazy Calc, so value hasn't been invoked yet. - assert (poll_invocations, value_invocations) == (2, 0) + assert (poll_invocations, value_invocations) == (1, 0) @effect() def _(): value_func() await flush() - assert (poll_invocations, value_invocations) == (2, 1) + assert (poll_invocations, value_invocations) == (1, 1) await flush() - assert (poll_invocations, value_invocations) == (2, 1) + assert (poll_invocations, value_invocations) == (1, 1) await mock_time.advance_time(1.01) # poll_invocations advances without a flush() because invalidate_later itself # invokes flush() - assert (poll_invocations, value_invocations) == (3, 1) + assert (poll_invocations, value_invocations) == (2, 1) await flush() - assert (poll_invocations, value_invocations) == (3, 1) + assert (poll_invocations, value_invocations) == (2, 1) # Now change value poll_return1 += 1 await flush() # Nothing changes because no time has passed, poll() has not tried again - assert (poll_invocations, value_invocations) == (3, 1) + assert (poll_invocations, value_invocations) == (2, 1) await mock_time.advance_time(1.01) - assert (poll_invocations, value_invocations) == (4, 2) + assert (poll_invocations, value_invocations) == (3, 2) # When a reactive dependency of poll_func invalidates, there's no need to wait # until the next poll with isolate(): poll_return2.set(poll_return2() + 1) await flush() - assert (poll_invocations, value_invocations) == (5, 3) + assert (poll_invocations, value_invocations) == (4, 3) # When a reactive dependency of value_func invalidates, there's no need to wait # until the next poll with isolate(): value_dep.set(value_dep() + 1) await flush() - assert (poll_invocations, value_invocations) == (5, 4) + assert (poll_invocations, value_invocations) == (4, 4) await mock_time.advance_time(1.01) - assert (poll_invocations, value_invocations) == (6, 4) + assert (poll_invocations, value_invocations) == (5, 4) @pytest.mark.asyncio From 50c5b348407bbd30895ca851a3dd54aa4ce88e0b Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 25 Nov 2026 15:48:44 -0500 Subject: [PATCH 4/6] fix(reactive): start poll()'s last value unset and req() it in the reader Replace the placeholder object with an unset reactive.Value. Readers of the decorated function now wait for the first poll instead of running the expensive read before it and again after it. Add a test for a reader that runs before the first poll, and credit the author in the changelog. --- CHANGELOG.md | 2 +- shiny/reactive/_poll.py | 23 +++++++++++----------- tests/pytest/test_poll.py | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef003e87af..bfd8325fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes and minor improvements -* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`. Previously `@poll()` called the function without awaiting it and kept the un-awaited coroutine as the "previous value", so a custom `equals` raised on its first comparison and every later poll failed with the same error. `poll_func` is also no longer called once when `@poll()` is applied: the polling effect reads the first value when it first runs. (#2576) +* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`. Previously `@poll()` called the function without awaiting it and kept the un-awaited coroutine as the "previous value", so a custom `equals` raised on its first comparison and every later poll failed with the same error. `poll_func` is also no longer called when `@poll()` is applied; the polling effect reads the first value. Until it does, reading the decorated function raises a silent exception, so outputs that render before the first poll wait for it instead of reading the data twice. (Thanks, @pcbeingused333!) (#2576) * On Windows, an output's busy indicator now shows while the output renders. Previously, when a synchronous render function blocked the event loop, the message that turns on the indicator reached the browser together with the output's new value, so most outputs never showed it (#1381). diff --git a/shiny/reactive/_poll.py b/shiny/reactive/_poll.py index 1a4663998c..e155e7d1fb 100644 --- a/shiny/reactive/_poll.py +++ b/shiny/reactive/_poll.py @@ -7,6 +7,7 @@ from .. import _utils, otel, reactive from .._docstring import add_example +from .._validation import req from ..types import MISSING, MISSING_TYPE if TYPE_CHECKING: @@ -16,10 +17,6 @@ T = TypeVar("T") -# Stands in for the first `poll_func` value of an async `poll_func`, which the polling -# effect reads on its first run. -_NO_VALUE: Any = object() - @add_example() def poll( @@ -102,9 +99,10 @@ def poll( """ with otel.suppress(): - # The first value is read by the effect below; calling `poll_func` here would also - # run it outside the polling loop, and an async one can't be awaited. - last_value: reactive.Value[Any] = reactive.Value(_NO_VALUE) + # Starts unset: the effect below reads the first value (an async `poll_func` + # can't be awaited here). Until then, the decorated function `req()`s it, and + # its readers re-run once the first value is set. + last_value: reactive.Value[Any] = reactive.Value() last_error: reactive.Value[Optional[Exception]] = reactive.Value(None) @reactive.effect(priority=priority, session=session) @@ -116,10 +114,11 @@ async def _(): new = poll_func() with reactive.isolate(): - old = last_value.get() + has_old = last_value.is_set() + old = last_value.get() if has_old else None try: - is_equal = False if old is _NO_VALUE else equals(old, new) + is_equal = has_old and equals(old, new) except Exception as e: # For example, pandas DataFrame throws if you try to compare it to a # non-comparable object @@ -177,7 +176,8 @@ async def result_async() -> T: if err is not None: raise err - # Take dependency on polling result + # Wait for the first poll, then take a dependency on its result + req(last_value.is_set()) last_value.get() # Note that we also depend on the main function @@ -200,7 +200,8 @@ def result_sync() -> T: if err is not None: raise err - # Take dependency on polling result + # Wait for the first poll, then take a dependency on its result + req(last_value.is_set()) last_value.get() # Note that we also depend on the main function diff --git a/tests/pytest/test_poll.py b/tests/pytest/test_poll.py index dab384d2e6..c62069f9fe 100644 --- a/tests/pytest/test_poll.py +++ b/tests/pytest/test_poll.py @@ -178,6 +178,46 @@ def value_func(): assert value_func() == "data" +@pytest.mark.asyncio +@pytest.mark.parametrize("is_async", [False, True]) +async def test_poll_reader_runs_before_first_poll(is_async: bool): + # A consumer that runs before the polling effect (here, because the polling effect + # has a lower priority) must not cause the expensive read function to run twice. + async with OnEndedSessionCallbacks(): + poll_invocations = 0 + value_invocations = 0 + + def sync_poll_func(): + nonlocal poll_invocations + poll_invocations += 1 + return 1 + + async def async_poll_func(): + return sync_poll_func() + + @poll(async_poll_func if is_async else sync_poll_func, priority=-1) + def value_func(): + nonlocal value_invocations + value_invocations += 1 + return "data" + + seen: list[str] = [] + + @effect() + def _(): + seen.append(value_func()) + + mock_time = MockTime() + with mock_time(): + await flush() + assert (poll_invocations, value_invocations) == (1, 1) + assert seen == ["data"] + + await mock_time.advance_time(1.01) + assert (poll_invocations, value_invocations) == (2, 1) + assert seen == ["data"] + + @pytest.mark.asyncio async def test_poll_errors(): async with OnEndedSessionCallbacks(): From 84748ef12d455f09c9d0ece0ead51701ffc48617 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 25 Nov 2026 16:02:32 -0500 Subject: [PATCH 5/6] refactor(reactive): drop redundant req() in poll() and test first-poll errors Value.get() already raises a silent exception while unset and takes the dependency first, so the req(last_value.is_set()) calls did nothing. Move the equals() checks under an if block for the first poll. Add tests for a first poll that raises and for file_reader() with a missing file, and shorten the changelog entry. --- CHANGELOG.md | 2 +- shiny/reactive/_poll.py | 72 +++++++++++++++++++++------------------ tests/pytest/test_poll.py | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfd8325fd7..fb65070d0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes and minor improvements -* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`. Previously `@poll()` called the function without awaiting it and kept the un-awaited coroutine as the "previous value", so a custom `equals` raised on its first comparison and every later poll failed with the same error. `poll_func` is also no longer called when `@poll()` is applied; the polling effect reads the first value. Until it does, reading the decorated function raises a silent exception, so outputs that render before the first poll wait for it instead of reading the data twice. (Thanks, @pcbeingused333!) (#2576) +* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`; previously every poll failed. `poll_func` is no longer called when `@poll()` is applied, so readers wait for the first poll. For `reactive.file_reader()`, a missing file no longer raises when the decorator is applied; the error is raised when the value is read. (Thanks, @pcbeingused333!) (#2576) * On Windows, an output's busy indicator now shows while the output renders. Previously, when a synchronous render function blocked the event loop, the message that turns on the indicator reached the browser together with the output's new value, so most outputs never showed it (#1381). diff --git a/shiny/reactive/_poll.py b/shiny/reactive/_poll.py index e155e7d1fb..6c2ade8ac4 100644 --- a/shiny/reactive/_poll.py +++ b/shiny/reactive/_poll.py @@ -7,7 +7,6 @@ from .. import _utils, otel, reactive from .._docstring import add_example -from .._validation import req from ..types import MISSING, MISSING_TYPE if TYPE_CHECKING: @@ -100,8 +99,8 @@ def poll( with otel.suppress(): # Starts unset: the effect below reads the first value (an async `poll_func` - # can't be awaited here). Until then, the decorated function `req()`s it, and - # its readers re-run once the first value is set. + # can't be awaited here). Until then, `last_value.get()` in the decorated + # function raises a silent exception, and its readers re-run once it is set. last_value: reactive.Value[Any] = reactive.Value() last_error: reactive.Value[Optional[Exception]] = reactive.Value(None) @@ -115,35 +114,40 @@ async def _(): with reactive.isolate(): has_old = last_value.is_set() - old = last_value.get() if has_old else None - - try: - is_equal = has_old and equals(old, new) - except Exception as e: - # For example, pandas DataFrame throws if you try to compare it to a - # non-comparable object - raise TypeError( - "The reactive.poll polling function returned an object that " - "couldn't be compared with a previously returned object. Try " - "modifying your polling function to return a simpler type, like a " - "str, float, list, or dict." - ) from e - if not isinstance(is_equal, bool): - # Comparison succeeded, but we don't understand the result - if equals is eq: - # We used == but it didn't work + + if has_old: + with reactive.isolate(): + old = last_value.get() + try: + is_equal = equals(old, new) + except Exception as e: + # For example, pandas DataFrame throws if you try to compare it + # to a non-comparable object raise TypeError( "The reactive.poll polling function returned an object " - "that doesn't implement a simple == operator. Try " - "modifying your polling function to return a simpler type, " - "like a str, float, list, or dict." - ) - else: - # The caller passed in a custom function - raise TypeError( - "The reactive.poll `equals` function returned a non-bool " - "value" - ) + "that couldn't be compared with a previously returned " + "object. Try modifying your polling function to return a " + "simpler type, like a str, float, list, or dict." + ) from e + if not isinstance(is_equal, bool): + # Comparison succeeded, but we don't understand the result + if equals is eq: + # We used == but it didn't work + raise TypeError( + "The reactive.poll polling function returned an " + "object that doesn't implement a simple == operator. " + "Try modifying your polling function to return a " + "simpler type, like a str, float, list, or dict." + ) + else: + # The caller passed in a custom function + raise TypeError( + "The reactive.poll `equals` function returned a " + "non-bool value" + ) + else: + # First poll: nothing to compare with + is_equal = False # If we got here, the comparison succeeded. Need to make sure the error is # cleared, but don't unnecessarily call last_error.set(); at the time of @@ -176,8 +180,8 @@ async def result_async() -> T: if err is not None: raise err - # Wait for the first poll, then take a dependency on its result - req(last_value.is_set()) + # Take dependency on polling result (raises a silent exception + # until the first poll sets it) last_value.get() # Note that we also depend on the main function @@ -200,8 +204,8 @@ def result_sync() -> T: if err is not None: raise err - # Wait for the first poll, then take a dependency on its result - req(last_value.is_set()) + # Take dependency on polling result (raises a silent exception + # until the first poll sets it) last_value.get() # Note that we also depend on the main function diff --git a/tests/pytest/test_poll.py b/tests/pytest/test_poll.py index c62069f9fe..837bfcf7c9 100644 --- a/tests/pytest/test_poll.py +++ b/tests/pytest/test_poll.py @@ -286,6 +286,65 @@ def _(): assert invocations == 3 +@pytest.mark.asyncio +async def test_poll_first_poll_raises(): + # When the first poll fails, there is no value yet. Readers must see the real + # error (not a silent exception), and a later successful poll must recover. + async with OnEndedSessionCallbacks(): + should_raise = True + + def poll_func() -> int: + if should_raise: + raise ValueError("boom") + return 1 + + @poll(poll_func) + def value_func() -> str: + return "data" + + mock_time = MockTime() + with mock_time(): + with isolate(): + await flush() + + with pytest.raises(ValueError, match="boom"): + value_func() + + should_raise = False + await mock_time.advance_time(1.01) + + assert value_func() == "data" + + +@pytest.mark.asyncio +async def test_file_reader_missing_file(): + # A missing file doesn't raise when @file_reader() is applied; the error is raised + # to whoever reads the value after the first poll. + with tempfile.TemporaryDirectory() as tmpdir: + path = os.path.join(tmpdir, "missing.txt") + + async with OnEndedSessionCallbacks(): + mock_time = MockTime() + with mock_time(): + + @file_reader(path) + def read_file(): + with open(path, "r") as f: + return f.read() + + with isolate(): + await flush() + + with pytest.raises(FileNotFoundError): + read_file() + + with open(path, "w") as f: + f.write("hello\n") + await mock_time.advance_time(1.01) + + assert read_file() == "hello\n" + + @pytest.mark.asyncio async def test_file_reader(): tmpfile = tempfile.NamedTemporaryFile(delete=False) From eebf1aaa605e117f1360d8a50387f5ea3404e2b1 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 25 Nov 2026 16:36:19 -0500 Subject: [PATCH 6/6] fix(examples): don't read poll() in the model-score server function deduplicate() read its function inside reactive.isolate() while the server function ran, which reached reactive.poll() before its first poll. Start the deduplicated value unset and let its effect set it. Also list the poll() change as a breaking change in the changelog. --- CHANGELOG.md | 4 +++- examples/model-score/plotly_streaming.py | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb65070d0a..47f36b79f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 (#2508, #2515) +* `reactive.poll()` and `reactive.file_reader()` no longer call `poll_func` when the decorator is applied; the first value comes from the first poll, in the first reactive flush. Until then, reading the decorated function raises a silent exception. Reading it from inside an output, calc, or effect works as before: the reader waits for the first poll and runs again once it lands. Code that reads it outside the reactive runtime, for example in `reactive.isolate()` while the server function runs, now raises instead of getting the value; move that read into a calc or effect. For `reactive.file_reader()`, a missing file no longer raises when the decorator is applied; the error is raised when the value is read (#2576). + * `near_points(add_dist=True)`, imported from `shiny.plotutils`, now names its distance column `dist_` instead of `dist`. Code reading `df["dist"]` from the result must now read `df["dist_"]` (#2510). ### Lifecycle changes @@ -47,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes and minor improvements -* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`; previously every poll failed. `poll_func` is no longer called when `@poll()` is applied, so readers wait for the first poll. For `reactive.file_reader()`, a missing file no longer raises when the decorator is applied; the error is raised when the value is read. (Thanks, @pcbeingused333!) (#2576) +* `reactive.poll()` now works with an `async` `poll_func` and a custom `equals`; previously every poll failed. (Thanks, @pcbeingused333!) (#2576) * On Windows, an output's busy indicator now shows while the output renders. Previously, when a synchronous render function blocked the event loop, the message that turns on the indicator reached the browser together with the output's new value, so most outputs never showed it (#1381). diff --git a/examples/model-score/plotly_streaming.py b/examples/model-score/plotly_streaming.py index e18c1439b2..99ecfcd336 100644 --- a/examples/model-score/plotly_streaming.py +++ b/examples/model-score/plotly_streaming.py @@ -82,14 +82,15 @@ def update_plotly_data(): def deduplicate(func): - with reactive.isolate(): - rv = reactive.value(func()) + # Starts unset; the effect below sets it once `func()` has a value. Reading it + # before then raises a silent exception, and readers re-run once it is set. + rv = reactive.value() @reactive.effect def update(): x = func() with reactive.isolate(): - if x != rv(): + if not rv.is_set() or x != rv(): rv.set(x) @reactive.calc