-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
196 lines (108 loc) · 5.95 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
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output,session) {
#Reading the File
RawData=read.csv("loyality.csv.csv",stringsAsFactors = TRUE)
#levels(RawData$Sales.Representative)[levels(RawData$Sales.Representative)==""]<- "no sales representative"
#select Input Codes
#For the Year
observe({
updateSelectInput(session,"year","year",choices =unique(RawData$Year),selected = "2018")
})
#FOr the Month
observe({
req(input$month)
updateSelectInput(session,"month","Month",choices=unique(RawData$Month),selected =unique(RawData$Month))})
#FOr the ORganization
observe({
req(input$organization)
updateSelectInput(session,inputId = "organization","Organization",choices = unique(RawData$Organization),selected = unique(RawData$Organization))})
#For the weekdays
observe({
req(input$weekday)
updateSelectInput(session,inputId = "weekday",choices = unique(RawData$Weekday),selected = unique(RawData$Weekday))})
#value boxes
#value box for Net amount
output$NetAmount = renderValueBox({
filtered<-RawData%>%
filter(Month.of.Year %in% input$month & Organization %in% input$organization& Weekday %in% input$weekday)%>%
select(Net.Amount)
sum=sum(filtered$Net.Amount)
valueBox(value=sum,"Net Amount")})
#value box for NetQuantity
output$Quantity=renderValueBox(
{
filteredquanity<-RawData%>%
filter(Month.of.Year %in% input$month & Organization %in% input$organization & Weekday %in% input$weekday)%>%
select(Net.Quantity)
sumquantity=sum(filteredquanity$Net.Quantity)
valueBox(value = sumquantity,"Net Quantity")
}
)
#graph for the month and net amount
output$monthgraph=renderPlotly({
filtereds<-RawData%>%
filter(Month.of.Year %in% input$month & Organization %in% input$organization & Weekday %in% input$weekday )%>%
select(Net.Amount,Month.of.Year)
month1=aggregate(filtereds$Net.Amount,by = list(filtereds$Month.of.Year), sum )
if(is.null(input$month)|is.null(input$organization)|is.null(input$weekday))
{
plotly(RawData)
}
else{
ggplotly(ggplot(data=month1, aes(x=month1$Group.1, y=month1$x, group=1)) +
geom_line(color="red")+
geom_point() )%>% config(displayModeBar= F) %>% config(showLink=F)%>% layout(xaxis=list(title = "Months"),yaxis = list(title = "Net Amount"))
}
})
#doughnut graph
output$doughnut=renderPlotly({
filteredpos<-RawData%>%
filter(Month.of.Year %in% input$month & Organization %in% input$organization & Weekday %in% input$weekday)%>%
select(POS.Terminal.Type)
p <- data.frame(table(RawData$POS.Terminal.Type))
plot_ly(p,labels = p$Var1, values = p$Freq) %>%
add_pie(hole = 0.7) %>%
layout(showlegend = F,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))%>% config(displayModeBar= F) %>% config(showLink=F)%>%layout(paper_bgcolor="transparent")
})
#Pie chart for the sales Reprentatives
output$pierepresent=renderPlotly({
filteredrep<-RawData%>%
filter(Month.of.Year %in% input$month & Organization %in% input$organization & Weekday %in% input$weekday)%>%
select(Sales.Representative)
q <- data.frame(table(filteredrep$Sales.Representative))
plot_ly(q, labels = q$Var1, values = q$Values, type = 'pie',
textposition = 'inside',
textinfo = 'label+percent',
insidetextfont = list(color = '#FFFFFF'),
hoverinfo = 'text',
marker = list(colors = colors,
line = list(color = '#FFFFFF', width = 1)),
#The 'pull' attribute can also be used to create space between the sectors
showlegend = FALSE) %>%
layout(title = '',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels =FALSE))%>% config(displayModeBar= F) %>% config(showLink=F)%>%layout(paper_bgcolor="transparent")
})
#Comparitive histogram
output$histogram<- renderPlotly({
filtered<-RawData%>%
filter(Month.of.Year %in% input$month & Organization %in% input$organization & Weekday %in% input$weekday)%>%
select(Net.Amount,Month.of.Year,Weekday)
ggplotly(ggplot(filtered, aes(filtered$Month.of.Year, filtered$Net.Amount)) + geom_bar(aes(fill = filtered$Weekday),
width = 0.4, position = position_dodge(width=0.5), stat="identity") +
theme(legend.position="top", legend.title =
element_blank(),axis.title.x=element_blank(),
axis.title.y=element_blank()))%>% config(displayModeBar= F) %>% config(showLink=F)%>%layout(paper_bgcolor="transparent")%>% layout(xaxis=list(title = "Months"),yaxis = list(title = "Net Amount"))
})
})