-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.R
108 lines (86 loc) · 3.08 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
library(shiny);
source("lib.R");
shinyServer(function(input, output) {
output$about <- renderText(paste('<iframe src="',
'http://ghbtns.com/github-btn.html?',
'user=henvic&repo=accidents&type=fork&size=large&count=true"',
'allowtransparency="true"',
'frameborder="0"',
'scrolling="0"',
'width="170"',
'height="30"',
'></iframe>',
sep = ''
));
output$distTable <- renderTable({
frequencyFunction <- paste("lib.intervalFunctions.",
input$frequencyFunction,
sep = "");
dataset <- lib.getData(input$dataset);
entries <- lib.getDeathsByStates(dataset);
if (!exists(frequencyFunction)) {
stop("Frequency function not available.");
return(null);
}
lib.renderFrequencyTable(entries, get(frequencyFunction));
});
output$distQualitativeTable <- renderTable({
dataset <- lib.getData(input$dataset);
entries <- lib.getDeathsByStates(dataset);
states <- lib.getDeathsStates(dataset);
lib.renderQualitativeTable(entries, states);
});
output$distProperties <- renderText({
dataset <- lib.getData(input$dataset);
entries <- lib.getDeathsByStates(dataset);
paste(lib.getSummary(entries));
});
output$distPlot <- renderPlot({
dataset <- lib.getData(input$dataset);
entries <- lib.getDeathsByStates(dataset);
states <- lib.getDeathsStates(dataset);
if (input$graph == "Histogram") {
bins <- seq(0, max(entries), length.out = input$bins + 1);
lib.plotHistogram(entries, bins);
output$distPlotNotes <- renderText(paste("Ideal bins:",
lib.intervalFunctions.square(entries), "(square),",
lib.intervalFunctions.sturges(entries), "(sturges),",
lib.intervalFunctions.scott(entries), "(Scoot),",
lib.intervalFunctions.FD(entries), "(FD)."
));
return(NULL);
}
if (input$graph == "Normal distribution") {
lib.plotNormal(mean(entries), sd(entries), input$confidence);
output$distPlotNotes <- renderText("");
return(NULL);
}
if (input$graph == "Hypothesis test") {
if (input$hypothesisTestSamples == "one") {
hypothesis <- lib.hypothesisTestOneSample(entries,
input$hypothesisTestType,
input$confidence,
sample(entries, ceiling(length(entries) / 10)));
output$distPlotNotes <- renderText(hypothesis);
return(NULL);
}
hypothesis <- lib.hypothesisTestTwoSamples(entries,
input$hypothesisTestType,
input$confidence,
sample(entries, ceiling(length(entries) / 10)),
sample(entries, ceiling(length(entries) / 10)));
output$distPlotNotes <- renderText(hypothesis);
return(NULL);
}
if (input$graph == "Qualitative") {
plotFunction <- paste("lib.plotFunctions.", input$plot, sep = "");
if (!exists(plotFunction)) {
stop("Plot function not available.");
return(null);
}
get(plotFunction)(entries, states);
output$distPlotNotes <- renderText("");
return(NULL);
}
});
});