-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
210 lines (155 loc) · 4.54 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
library(shiny)
library(RMySQL)
flag<-0
MySQL.<-MySQL()
con=dbConnect(MySQL.,user='root', password='insead',dbname='insead')
dbSendQuery(con,"update scores set num=0 where id=1985")
# Define server logic for random distribution application
shinyServer(function(input, output) {
myscore1<-reactive({
if (input$b1==0)
return()
else
{
dbSendQuery(con,"update scores set num=num-1 where id=1985")
dbGetQuery(con,"select num from scores where id=1985")}
})
myscore2<-reactive({
if (input$b2==0)
return()
else
{
dbSendQuery(con,"update scores set num=num+1 where id=1985")
dbGetQuery(con,"select num from scores where id=1985")}
})
output$score1<-renderTable({
myscore1()
})
output$score2<-renderTable({
myscore2()
})
output$fq2<-renderTable({
fq2()
})
output$fq3<-renderTable({
fq3()
})
choicesInput<-reactive({
input$choices
})
output$caption<-renderText({
choicesInput()
})
output$downloadPDF <-
downloadHandler(filename = "report.pdf",
content = function(file)
{
#texi2pdf("report.tex")
#knit2pdf("report.Rnw",output="report.pdf")
file.copy("report.pdf", file)
}
,
contentType = "application/pdf"
)
observe({
ss<-dbGetQuery(con,"select num from scores where id=1985")
if (as.integer(ss)<=1)
dbGetQuery(con, "select results from reporting")
})
observe({
ss<-dbGetQuery(con,"select num from scores where id=1985")
if (as.integer(ss)==2)
dbGetQuery(con, "select results2 from reporting")
})
observe({
ss<-dbGetQuery(con,"select num from scores where id=1985")
if (as.integer(ss)>2)
dbGetQuery(con, "select result3 from reporting")
})
output$r3<-renderTable({
reporting3()
})
output$reporting<-renderTable({
dbGetQuery(con,"select * from reporting")
})
output$squestions<-renderTable({
dbGetQuery(con,"select * from small")
})
output$mquestions<-renderTable({
dbGetQuery(con,"select * from medium")
})
output$lquestions<-renderTable({
dbGetQuery(con,"select * from large")
})
observe({
if (input$b1 == 0)
return()
ifoption1<-reactive({
id<-sample(1:3,1,replace=T)
query<-paste("select option1,option2 from medium where id='",id,"'",sep="")
dbGetQuery(con, query)
})
output$qq1<-renderTable({
ifoption1()
})
output$nui<-renderUI({
tableOutput("qq1")
})
output$noption<-renderUI({
helpText("in the previous question you have selected option1")
})
output$nsb<-renderUI({
submitButton("calculate and next question")
})
})
observe({
if (input$b2 == 0)
return()
ifoption2<-reactive({
id<-sample(1:3,1,replace=T)
query<-paste("select option1,option2 from large where id='",id,"'",sep="")
dbGetQuery(con, query)})
output$qq2<-renderTable({
ifoption2()
})
output$nui<-renderUI({
tableOutput("qq2")
})
output$noption<-renderUI({
helpText("in the previous question you have selected option2")
})
output$nsb<-renderUI({
submitButton("calculate and next question")
})
})
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The output renderers defined
# below then all used the value computed from this expression
data <- reactive({
dist <- switch(input$dist,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
dist(input$n)
})
# Generate a plot of the data. Also uses the inputs to build the
# plot label. Note that the dependencies on both the inputs and
# the data reactive expression are both tracked, and all expressions
# are called in the sequence implied by the dependency graph
output$plot <- renderPlot({
dist <- input$dist
n <- input$n
hist(data(),
main=paste('r', dist, '(', n, ')', sep=''))
})
# Generate a summary of the data
output$summary <- renderPrint({
summary(data())
})
# Generate an HTML table view of the data
output$table <- renderTable({
data.frame(x=data())
})
})