|
| 1 | +# pyright: reportUnknownMemberType=false, reportUnknownVariableType=false |
1 | 2 | import matplotlib.pyplot as plt |
2 | 3 | import numpy as np |
3 | 4 |
|
4 | | -from shiny import App, Inputs, Outputs, Session, render, ui |
| 5 | +from shiny.express import input, render, session, ui |
5 | 6 |
|
6 | | -app_ui = ui.page_sidebar( |
7 | | - ui.sidebar( |
8 | | - ui.input_slider("obs", "Number of observations:", min=0, max=1000, value=500), |
9 | | - open="closed", |
10 | | - ), |
11 | | - ui.h3("clientData values"), |
12 | | - ui.output_text_verbatim("clientdatatext"), |
13 | | - ui.output_plot("myplot"), |
14 | | - title="Shiny Client Data", |
15 | | -) |
| 7 | +with ui.sidebar(open="closed"): |
| 8 | + ui.input_slider("obs", "Number of observations:", min=0, max=1000, value=500) |
16 | 9 |
|
17 | 10 |
|
18 | | -def server(input: Inputs, output: Outputs, session: Session): |
19 | | - @render.text |
20 | | - def clientdatatext(): |
21 | | - cdata = session.clientdata |
22 | | - return "\n".join([f"{name} = {cdata[name]()}" for name in reversed(dir(cdata))]) |
| 11 | +@render.code |
| 12 | +def clientdatatext(): |
| 13 | + cdata = session.clientdata |
| 14 | + return "\n".join([f"{name} = {cdata[name]()}" for name in reversed(dir(cdata))]) |
23 | 15 |
|
24 | | - @render.plot |
25 | | - def myplot(): |
26 | | - plt.figure() |
27 | | - plt.hist(np.random.normal(size=input.obs())) |
28 | | - plt.title("This is myplot") |
29 | 16 |
|
30 | | - |
31 | | -app = App(app_ui, server) |
| 17 | +@render.plot |
| 18 | +def myplot(): |
| 19 | + plt.figure() |
| 20 | + plt.hist(np.random.normal(size=input.obs())) # type: ignore |
| 21 | + plt.title("This is myplot") |
0 commit comments