|
1 | 1 | import matplotlib.pyplot as plt |
2 | 2 | import numpy as np |
3 | 3 |
|
4 | | -from shiny import App, Inputs, Outputs, Session, reactive, render, ui |
| 4 | +from shiny import reactive, render |
| 5 | +from shiny.express import input, ui |
5 | 6 |
|
6 | | -app_ui = ui.page_fluid( |
7 | | - ui.input_slider("n", "Number of observations", min=0, max=1000, value=500), |
8 | | - ui.input_action_button("go", "Go!", class_="btn-success"), |
9 | | - ui.output_plot("plot"), |
10 | | -) |
11 | 7 |
|
| 8 | +ui.input_slider("n", "Number of observations", min=0, max=1000, value=500) |
| 9 | +ui.input_action_button("go", "Go!", class_="btn-success") |
12 | 10 |
|
13 | | -def server(input: Inputs, output: Outputs, session: Session): |
14 | | - @render.plot(alt="A histogram") |
15 | | - # Use reactive.event() to invalidate the plot only when the button is pressed |
16 | | - # (not when the slider is changed) |
17 | | - @reactive.event(input.go, ignore_none=False) |
18 | | - def plot(): |
19 | | - np.random.seed(19680801) |
20 | | - x = 100 + 15 * np.random.randn(input.n()) |
21 | | - fig, ax = plt.subplots() |
22 | | - ax.hist(x, bins=30, density=True) |
23 | | - return fig |
24 | 11 |
|
25 | | - |
26 | | -app = App(app_ui, server) |
| 12 | +@render.plot(alt="A histogram") |
| 13 | +# Use reactive.event() to invalidate the plot only when the button is pressed |
| 14 | +# (not when the slider is changed) |
| 15 | +@reactive.event(input.go, ignore_none=False) |
| 16 | +def plot(): |
| 17 | + np.random.seed(19680801) |
| 18 | + x = 100 + 15 * np.random.randn(input.n()) |
| 19 | + fig, ax = plt.subplots() |
| 20 | + ax.hist(x, bins=30, density=True) |
| 21 | + return fig |
0 commit comments