Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix render.download in Shiny Express, take 2 #1085

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading