Skip to content

Conditional @render.download button in shiny express #1365

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

Closed
isthisthat opened this issue May 9, 2024 · 2 comments
Closed

Conditional @render.download button in shiny express #1365

isthisthat opened this issue May 9, 2024 · 2 comments

Comments

@isthisthat
Copy link

Hello, is there a way to condition (or @render.ui) a @render.download button in shiny express? My specific use-case is if a row is selected in a DataGrid, show the download button. Thanks!

@wch
Copy link
Collaborator

wch commented May 9, 2024

You can use render.express, which is similar to using render.ui, except where render.ui requires the function to return the UI components, render.express allows you to write code with Express syntax, where the UI components are automatically captured from evaluating the code.

Live example

from pathlib import Path
from shiny.express import ui, render, expressify, input

ui.input_select("show_hide", "Show or hide download", {"hide": "Hide", "show": "Show"})


@render.express
def download_ui():
    if input.show_hide() == "show":

        @render.download()
        def download1():
            path = Path(__file__).parent / "mtcars.csv"
            return str(path)

@isthisthat
Copy link
Author

Wow that worked beautifully! Thanks @wch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants