diff --git a/CHANGELOG.md b/CHANGELOG.md index 826144ea3..530c45432 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [UNRELEASED] +* Fixed `render.download` not working in Express. (#1085) ## [0.7.0] - 2024-01-25 diff --git a/shiny/api-examples/download_button/app-express.py b/shiny/api-examples/download_button/app-express.py new file mode 100644 index 000000000..96bd64273 --- /dev/null +++ b/shiny/api-examples/download_button/app-express.py @@ -0,0 +1,15 @@ +import asyncio +import random +from datetime import date + +from shiny.express import render + + +@render.download( + filename=lambda: f"新型-{date.today().isoformat()}-{random.randint(100,999)}.csv" +) +async def downloadData(): + await asyncio.sleep(0.25) + yield "one,two,three\n" + yield "新,1,2\n" + yield "型,4,5\n" diff --git a/shiny/render/_render.py b/shiny/render/_render.py index adb9cf6df..81fb7a10c 100644 --- a/shiny/render/_render.py +++ b/shiny/render/_render.py @@ -30,6 +30,7 @@ from .._docstring import add_example, no_example from .._namespaces import ResolvedId from .._typing_extensions import Self +from ..express._mock_session import MockSession from ..session import get_current_session, require_active_session from ..session._session import DownloadHandler, DownloadInfo from ..types import MISSING, MISSING_TYPE, ImgData @@ -688,7 +689,7 @@ def url() -> str: # not being None is because in Express, when the UI is rendered, this function # `render.download()()` called once before any sessions have been started. session = get_current_session() - if session is not None: + if session is not None and not isinstance(session, MockSession): session._downloads[self.output_id] = DownloadInfo( filename=self.filename, content_type=self.media_type,