Skip to content

Commit 1771cff

Browse files
committed
expressify shiny/api-examples/input_action_button
1 parent 5e2b364 commit 1771cff

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
from shiny import reactive, render
5+
from shiny.express import input, ui
6+
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")
10+
11+
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)