-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.R
68 lines (48 loc) · 2.06 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
library(UsingR)
library(corrplot)
data(babies)
shinyServer(
function(input, output) {
filterDataset <- reactive({
minAge <- input$age[1]
maxAge <- input$age[2]
includeUnknowAge <- input$unknowAge
if(includeUnknowAge) {
filteredBabies <- babies[which((babies$age >= minAge & babies$age <= maxAge) | babies$age == 99),]
} else {
filteredBabies <- babies[which(babies$age >= minAge & babies$age <= maxAge),]
}
# 99 = All
if(input$smoke != 99) {
filteredBabies <- filteredBabies[filteredBabies$smoke == input$smoke,]
}
# 100 = All
if(input$cnumber != 100) {
filteredBabies <- filteredBabies[filteredBabies$number == input$cnumber,]
}
colnames(filteredBabies) <- c("id", "Pluralty", "Live Birth", "Date", "Gestation",
"Sex", "Birth Weight (Onces)", "Parity", "Mother's Race",
"Mother's Age", "Mother's Education", "Mother's Height", "Mother's Prepregnancy (Pounds)",
"Father's Race", "Father's Age", "Father's Education", "Father's Height",
"Father's Weight", "Marital", "Family Yearly Income", "Smoke", "Time Smoke Quit", "Cigarrets Number")
filteredBabies
})
output$dtTable1 <- renderDataTable(filterDataset())
output$hist <- renderPlot({
dataFiltered <- filterDataset()
if(nrow(dataFiltered) > 0) {
hist(dataFiltered$"Birth Weight (Onces)",xlab="Weight (Onces)",
main="Infant's Birth Weight",breaks=100)
abline(v = mean(dataFiltered$"Birth Weight (Onces)"), col = "blue", lwd = 2)
}
})
output$mean <- renderText({
dataFiltered <- filterDataset()
if(nrow(dataFiltered) > 0) {
paste("Infant's Weight Mean: ", round(mean(dataFiltered$"Birth Weight (Onces)"),2))
} else {
"No data found"
}
})
}
)