Skip to content

Commit bccfaa8

Browse files
committed
Rewrite app-express.py using Shiny Express
1 parent fdabbbd commit bccfaa8

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed
Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4-
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
4+
from shiny import reactive, render
5+
from shiny.express import input, ui
56

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-
)
117

8+
ui.input_slider("n", "Number of observations", min=0, max=1000, value=500)
9+
ui.input_action_button("go", "Go!", class_="btn-success")
1210

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
2411

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

Comments
 (0)