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

Consider replacing output_args() #971

Closed
Tracked by #969
wch opened this issue Jan 4, 2024 · 0 comments · Fixed by #977
Closed
Tracked by #969

Consider replacing output_args() #971

wch opened this issue Jan 4, 2024 · 0 comments · Fixed by #977
Milestone

Comments

@wch
Copy link
Collaborator

wch commented Jan 4, 2024

The output_args() function (added in #786) does the following: In Express, it allows passing arguments to the output function that's associated with a render function. For example, with the upcoming render.download() function (#967), it would look something like this:

@output_args(label="Download file")
@render.download(filename="hello.txt")
def dl:
    yield f"Hello, world! n = {input.n()}"

One major drawback is that the function signature accepts just *args and **kwargs, so it can't give any help for argument completion or typing. In the example above, you just have to know that the output UI function is download_button(), and look up the parameter names (and types) for that function.

Currently, if you want finer control and completion support, you can use @suspend_display and call the output UI function directly:

@suspend_display
@render.download(filename="hello.txt")
def dl:
    yield f"Hello, world! n = {input.n()}"

ui.download_button("dl", label="Download file")

The downside of this is that when the user just wants to customize a single parameter value, the code becomes a lot more verbose. And it's conceptually a bit of a leap to turn off the automatic UI, and then manually create it.

For the case of render_plot(), we've done something different: we added the output arguments to the render.plot() function. If we were to use that strategy here, it would look like this:

@render.download(filename="hello.txt", label="Download file")
def dl:
    yield f"Hello, world! n = {input.n()}"

This is concise, but it has the following drawbacks:

  • It's not immediately obvious to the user which arguments are for the output UI, and which are for the rendering step.
  • Those arguments are also present for Shiny Core, which may be confusing.

Another way we could go is to have a method for setting UI output arguments, that chains off the renderer object:

@render.download(filename="hello.txt").ui_args(label="Download file")
def dl:
    yield f"Hello, world! n = {input.n()}"
@wch wch added this to the v0.7.0 milestone Jan 4, 2024
This was referenced Jan 4, 2024
@wch wch closed this as completed in #977 Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant