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

Add clientdata accessor to session; allow access to input names via dir() #1832

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jan 30, 2025

Closes #623
Closes #711

Here's an example to replicate the one on this page https://shiny.posit.co/r/articles/build/client-data/

app.py
import matplotlib.pyplot as plt
import numpy as np

from shiny import App, Session, render, ui

app_ui = ui.page_sidebar(
    ui.sidebar(
        ui.input_slider("obs", "Number of observations:", min=0, max=1000, value=500)
    ),
    ui.h3("clientData values"),
    ui.output_text_verbatim("clientdatatext"),
    ui.output_plot("myplot"),
    title="Shiny Client Data",
)


def server(input, output, session: Session):
    @render.text
    def clientdatatext():
        cdata = session.clientdata
        return "\n".join([f"{name} = {cdata[name]()}" for name in dir(cdata)])

    @render.plot
    def myplot():
        plt.figure()
        plt.hist(np.random.normal(size=input.obs()))
        plt.title("Generated in @render.plot")


app = App(app_ui, server)
Screenshot 2025-01-29 at 6 37 38 PM

TODO

@cpsievert cpsievert changed the title Add clientdata accessor to session Add clientdata accessor to session; allow access to input names via dir() Jan 30, 2025
@cpsievert cpsievert requested a review from gadenbuie January 30, 2025 00:38
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.

Missing .clientdata accessors Expose clientData on session object
1 participant