viapascurta commited on
Commit
bab94b2
·
verified ·
1 Parent(s): bdc3df0

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This app is translated from Mastering Shinywidgets
2
+ # https://mastering-shiny.org/basic-reactivity.html#reactive-expressions-1
3
+ from shiny import App, render, ui
4
+ from numpy import random
5
+
6
+ # Functions we import from stats.py
7
+ from stats import freqpoly, t_test
8
+
9
+ app_ui = ui.page_fluid(
10
+ ui.row(
11
+ ui.column(
12
+ 4,
13
+ "Distribution 1",
14
+ ui.input_numeric("n1", label="n", value=1000, min=1),
15
+ ui.input_numeric("mean1", label="µ", value=0, step=0.1),
16
+ ui.input_numeric("sd1", label="σ", value=0.5, min=0.1, step=0.1),
17
+ ),
18
+ ui.column(
19
+ 4,
20
+ "Distribution 2",
21
+ ui.input_numeric("n2", label="n", value=1000, min=1),
22
+ ui.input_numeric("mean2", label="µ", value=0, step=0.1),
23
+ ui.input_numeric("sd2", label="σ", value=0.5, min=0.1, step=0.1),
24
+ ),
25
+ ui.column(
26
+ 4,
27
+ "Frequency polygon",
28
+ ui.input_numeric("binwidth", label="Bin width", value=0.1, step=0.1),
29
+ ui.input_slider("range", label="range", value=[-3, 3], min=-5, max=5),
30
+ ),
31
+ ),
32
+ ui.row(
33
+ ui.column(9, ui.output_plot("hist")),
34
+ ui.column(3, ui.output_text_verbatim("ttest")),
35
+ ),
36
+ )
37
+
38
+
39
+ def server(input, output, session):
40
+ @output
41
+ @render.plot
42
+ def hist():
43
+ print(input.range())
44
+ x1 = random.normal(input.mean1(), input.sd1(), input.n1())
45
+ x2 = random.normal(input.mean2(), input.sd2(), input.n2())
46
+ return freqpoly(x1, x2, input.binwidth(), input.range())
47
+
48
+ @output
49
+ @render.text
50
+ def ttest():
51
+ x1 = random.normal(0, 1, 100)
52
+ x2 = random.normal(0, 1, 100)
53
+ return t_test(x1, x2)
54
+
55
+
56
+ app = App(app_ui, server)