Skip to content

Conversation

pfalcon
Copy link

@pfalcon pfalcon commented Jun 8, 2025

The idea is similar to e.g. Python's dict.get() method, which can take an optional default if a given key doesn't exist in the dict.

This change would allow to users to "bootstrap" otherwise circular dependencies in simple cases. For example, it allows to turn this code:

from shiny.express import input, render, ui

@render.express
def myrender():
    ui.input_select("sel", None, ["All", "So", "Much"], selected="All")
    input.sel()

which doesn't render anything nor produces errors (underneath it throws SilentException which isn't reported) into following code:

from shiny.express import input, render, ui

@render.express
def myrender():
    ui.input_select("sel", None, ["All", "So", "Much"], selected=input.sel.get("All"))
    input.sel.get("All")

which works as expected (initial selected value is "All", and if user chooses another, it's preserved across myrender() run).

The idea is similar to e.g. Python's dict.get() method, which can take an
optional default if a given key doesn't exist in the dict.

This change would allow to users to "bootstrap" otherwise circular
dependencies in simple cases. For example, it allows to turn this
code:

```
from shiny.express import input, render, ui

@render.express
def myrender():
    ui.input_select("sel", None, ["All", "So", "Much"], selected="All")
    input.sel()
```

which doesn't render anything nor produces errors (underneath it throws
SilentException which isn't reported) into following code:

```
from shiny.express import input, render, ui

@render.express
def myrender():
    ui.input_select("sel", None, ["All", "So", "Much"], selected=input.sel.get("All"))
    input.sel.get("All")
```

which works as expected (initial selected value is "All", and if user
chooses another, it's preserved across myrender() run).
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 this pull request may close these issues.

1 participant