Skip to content

Commit

Permalink
Fix render.download in Shiny Express, take 2 (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
wch authored Jan 30, 2024
1 parent fc55acc commit 3612c21
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions shiny/api-examples/download_button/app-express.py
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion shiny/render/_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3612c21

Please sign in to comment.