-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
176 lines (149 loc) · 6.49 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
library(shiny)
library(shinydashboard)
library(vcd)
library(vcdExtra)
data_sets <- c("Choose from the following options...",
"Upload a CSV data file",
"Abortion Opinion Data",
"HairEyeSex Data",
"Employment Status Data",
"Pre-Marital Sex and Divorce Data",
"Titanic Data",
"Berkeley Admission Data",
"Infection in Cesarean Births Data",
"Suicide Data",
"Heart Disease Data")
shinyServer(function(input, output, session) {
output$choose_dataset <- renderUI({
selectInput("dataset", "Choose data set:", as.list(data_sets))
})
output$upload_dataset <- renderUI({
fileInput('file1', 'Choose file to upload',
multiple = FALSE,
accept = c('text/csv',
'text/comma-separated-values',
'.csv'))
})
output$choose_columns <- renderUI({
if(is.null(input$dataset))
return("\n")
dname <- switch(input$dataset,
"Choose from the following options..." = NULL,
"Upload a CSV file" = "choose",
"Abortion Opinion Data" = "Abortion",
"HairEyeSex Data" = "HairEyeColor",
"Employment Status Data" = "Employment",
"Pre-Marital Sex and Divorce Data" = "PreSex",
"Titanic Data" = "Titanic",
"Berkeley Admission Data" = "UCBAdmissions",
"Infection in Cesarean Births Data" = "Caesar",
"Suicide Data" = "Suicide",
"Heart Disease Data" = "Heart")
if(is.null(dname))
return("\n")
if (dname == "choose"){
inFile <- input$file1
if (is.null(inFile))
return(NULL)
dat <- read.csv(inFile$datapath)
} else dat <- get(dname)
if (class(dat) == "table") {
dat <- expand.dft(dat)
}
colnames <- names(dat)
checkboxGroupInput("columns",
label = "Variables to Include:",
choices = colnames,
selected = colnames)
})
data_set <- reactive({
if(is.null(input$dataset))
return("\n")
dname <- switch(input$dataset,
"Choose from the following options..." = NULL,
"Upload a CSV file" = "choose",
"Abortion Opinion Data" = "Abortion",
"HairEyeSex Data" = "HairEyeColor",
"Employment Status Data" = "Employment",
"Pre-Marital Sex and Divorce Data" = "PreSex",
"Titanic Data" = "Titanic",
"Berkeley Admission Data" = "UCBAdmissions",
"Infection in Cesarean Births Data" = "Caesar",
"Suicide Data" = "Suicide",
"Heart Disease Data" = "Heart")
if(is.null(dname))
return()
if (dname == "choose"){
inFile <- input$file1
if (is.null(inFile))
return(NULL)
dat <- read.csv(inFile$datapath)
} else dat <- get(dname)
if (class(dat) == "table") {
dat <- expand.dft(dat)
}
if (is.null(input$columns) || !(input$columns %in% names(dat)))
return()
dat <- dat[, input$columns, drop = FALSE]
})
output$xtabs <- renderPrint({
if(is.null(input$dataset))
return("\n")
rs <- paste(input$columns, collapse = "+")
if (input$freq == TRUE) {
f <- as.formula(paste(input$freqVar, "~", rs))
} else f <- as.formula(paste("~", rs))
print(xtabs(f, data = data_set()))
})
output$summary <- renderTable({
if(is.null(input$dataset))
return("\n")
summary(data_set())
}, include.rownames = FALSE)
output$mosaic <- renderPlot({
if(is.null(input$dataset))
return("\n")
ls <- paste(input$columns, collapse = "+")
if (input$freq == TRUE) {
f <- as.formula(paste(input$freqVar, "~", ls))
} else f <- as.formula(paste("~", ls))
mosaic(f, data = data_set(), shade = input$shading)
})
output$anova <- renderPrint({
if(is.null(input$dataset))
return("\n")
rs <- paste(input$columns, collapse = "+")
f <- as.formula(paste("~", rs))
ff1 <- xtabs(f, data = data_set())
ff2 <- as.data.frame(ff1)
f <- as.formula(paste("Freq ~", rs))
mod <- glm(f, data = ff2, family = "poisson")
print(anova(mod))
print(coef(mod))
})
# output$mosaic <- renderPlot({
# mod <- loglinear()
# # f <- switch(input$model,
# # "(SPT)"= c("Presence*Period*Temperature.category"),
# # "(SP,ST,PT)" = c("Presence*Period", "Presence*Temperature.category", "Period*Temperature.category"),
# # "(ST,PT)" = c("Presence*Temperature.category", "Period*Temperature.category"),
# # "(SP,PT)" = c("Presence*Period", "Period*Temperature.category"),
# # "(SP,ST)" = c("Presence*Period", "Presence*Temperature.category"))
#
# mod.glm <- glm(formula = reformulate(f, response = "Freq"), data = mod, family = poisson)
#
# mosaic.glm(mod.glm,
# formula = ~ Temperature.category + Period + Presence,
# gp = shading_hcl,
# spacing = spacing_highlighting,
# type = input$type,
# labeling_args = list(rot_labels = c(left = 0, right = 0),
# offset_varnames = c(left=1.5, right = 1),
# offset_labels = c(left=.5, right = .1),
# set_varnames = c(Temperature.category="Temperature", Period="Period",
# Presence="Status")),
# set_labels=list(Presence = c("Ab","Pr")),
# margins = c(right = 5, left = 4, bottom = 1, top =3 ))
# })
#
})