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

Should have a way of getting names of all inputs #873

Open
wch opened this issue Dec 7, 2023 · 0 comments
Open

Should have a way of getting names of all inputs #873

wch opened this issue Dec 7, 2023 · 0 comments

Comments

@wch
Copy link
Collaborator

wch commented Dec 7, 2023

Currently, if you want to get the name of all keys in input, you need to do call:

list(input._map)

This is kind of a hack. It should be possible to call list(input) or input.keys() to get the keys.

This app demonstrates (shinylive app):

from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.h2("All input keys:"),
    ui.output_text_verbatim("txt"),
    ui.input_slider("slider", "A slider", 1, 100, 50),
)


def server(input, output, session):
    @output
    @render.text
    def txt():
        keys = list(input._map)
        keys_values = [f'input["{k}"] = {str(input[k]())}' for k in keys]
        return "\n".join(keys_values)


app = App(app_ui, server)
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

No branches or pull requests

1 participant