Skip to content

Commit 3612c21

Browse files
authored
Fix render.download in Shiny Express, take 2 (#1085)
1 parent fc55acc commit 3612c21

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [UNRELEASED]
1010

11+
* Fixed `render.download` not working in Express. (#1085)
1112

1213

1314
## [0.7.0] - 2024-01-25
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import asyncio
2+
import random
3+
from datetime import date
4+
5+
from shiny.express import render
6+
7+
8+
@render.download(
9+
filename=lambda: f"新型-{date.today().isoformat()}-{random.randint(100,999)}.csv"
10+
)
11+
async def downloadData():
12+
await asyncio.sleep(0.25)
13+
yield "one,two,three\n"
14+
yield "新,1,2\n"
15+
yield "型,4,5\n"

shiny/render/_render.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .._docstring import add_example, no_example
3131
from .._namespaces import ResolvedId
3232
from .._typing_extensions import Self
33+
from ..express._mock_session import MockSession
3334
from ..session import get_current_session, require_active_session
3435
from ..session._session import DownloadHandler, DownloadInfo
3536
from ..types import MISSING, MISSING_TYPE, ImgData
@@ -688,7 +689,7 @@ def url() -> str:
688689
# not being None is because in Express, when the UI is rendered, this function
689690
# `render.download()()` called once before any sessions have been started.
690691
session = get_current_session()
691-
if session is not None:
692+
if session is not None and not isinstance(session, MockSession):
692693
session._downloads[self.output_id] = DownloadInfo(
693694
filename=self.filename,
694695
content_type=self.media_type,

0 commit comments

Comments
 (0)