-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.R
161 lines (147 loc) · 5.3 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
# Reading data set
my_data=read.table("data/sect_dataset.csv", header=T, sep=",")
my_data$Decade=as.factor(my_data$Decade)
server <- function(input, output) {
## stuffs for dashboard tab
output$vbox1 <- renderValueBox({
valueBox(
"Attacks: 1,098",
input$count,
color = "orange",
icon = icon("empire"))
})
output$vbox2 <- renderValueBox({
valueBox(
"Target Killing: 5,912",
input$count,
color = "red",
icon = icon("bullseye")
)
})
## stuffs for data tab
# data table output
output$da.tab <- DT::renderDataTable(datatable(my_data, extensions = 'Buttons',
style = "bootstrap",
filter = list(position = 'top', clear = T, plain = F),
options = list(pageLength = 1500, dom = 'Bfrtip',
buttons =
list('copy', 'print', list(
extend = 'collection',
buttons = c('csv', 'excel', 'pdf'),
text = 'Download')
)
)
)
)
## stuffs for data explorer
# for tab: Killed
output$plotPresKill <- renderPlotly({
# build graph with ggplot syntax
p1 <- ggplot(my_data, color = President) +
geom_jitter(aes(Killed, Province, color = President),
show.legend = T,
inherit.aes = T,
width = 0.2,
height = 0.5,
size = 2,
alpha =0.5) +
ggthemes::theme_gdocs() + scale_colour_gdocs()
ggplotly(p1)
})
output$plotGovKill <- renderPlotly({
p2 <- ggplot(my_data, color = Government) +
geom_jitter(aes(Killed, Province, color = Government),
show.legend = T,
inherit.aes = T,
width = 0.2,
height = 0.5,
size = 2,
alpha =0.5) +
ggthemes::theme_gdocs() + scale_colour_gdocs()
ggplotly(p2)
})
output$plotInciKill <- renderPlotly({
p3 <- ggplot(my_data, color = Incident) +
geom_jitter(aes(Killed, Province, color = Incident),
show.legend = T,
inherit.aes = T,
width = 0.2,
height = 0.5,
size = 2,
alpha =0.5) +
ggthemes::theme_gdocs() + scale_colour_gdocs()
ggplotly(p3)
})
output$plotDecKill <- renderPlotly({
p4 <- ggplot(my_data, color = Decade) +
geom_jitter(aes(Killed, Province, color = Decade),
show.legend = T,
inherit.aes = T,
width = 0.2,
height = 0.5,
size = 2,
alpha =0.5) +
ggthemes::theme_gdocs() + scale_colour_gdocs()
ggplotly(p4)
})
# for tab: Injured
output$plotPresInj <- renderPlotly({
# build graph with ggplot syntax
p5 <- ggplot(my_data, color = President) +
geom_jitter(aes(Injured, Province, color = President),
show.legend = T,
inherit.aes = T,
width = 0.2,
height = 0.5,
size = 2,
alpha =0.5) +
ggthemes::theme_gdocs() + scale_colour_gdocs()
ggplotly(p5)
})
output$plotGovInj <- renderPlotly({
p6 <- ggplot(my_data, color = Government) +
geom_jitter(aes(Injured, Province, color = Government),
show.legend = T,
inherit.aes = T,
width = 0.2,
height = 0.5,
size = 2,
alpha =0.5) +
ggthemes::theme_gdocs() + scale_colour_gdocs()
ggplotly(p6)
})
output$plotInciInj <- renderPlotly({
p7 <- ggplot(my_data, color = Incident) +
geom_jitter(aes(Injured, Province, color = Incident),
show.legend = T,
inherit.aes = T,
width = 0.2,
height = 0.5,
size = 2,
alpha =0.5) +
ggthemes::theme_gdocs() + scale_colour_gdocs()
ggplotly(p7)
})
output$plotDecInj <- renderPlotly({
p8 <- ggplot(my_data, color = Decade) +
geom_jitter(aes(Injured, Province, color = Decade),
show.legend = T,
inherit.aes = T,
width = 0.2,
height = 0.5,
size = 2,
alpha =0.5) +
ggthemes::theme_gdocs() + scale_colour_gdocs()
ggplotly(p8)
})
## stuffs for data comparison
output$OutPlot3 <- renderPlot({
p <- ggplot(my_data, aes(x=Killed, y=reorder(Province, Killed))) +
geom_segment(aes(yend = reorder(Province, Killed)), xend =0, colour = "grey50") +
geom_point(size=3, aes(colour = Incident), alpha =0.5) +
theme_bw() +
theme(panel.grid.major.y = element_line()) +
facet_grid(Government ~ .)
p
})
}