-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfitability.dashboard.R
More file actions
225 lines (183 loc) · 9.52 KB
/
Profitability.dashboard.R
File metadata and controls
225 lines (183 loc) · 9.52 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
## app.R ##
library(shiny)
library(shinydashboard)
library(ggplot2)
library(tidyverse)
library(plotly)
library(rsconnect)
QP2 <- read.csv("D7_Office.csv")
attach(QP2)
ui <- dashboardPage(
# Application title
dashboardHeader(title = "Profitability Dashboard"),
# Sidebar with Check Boxes to adjust output
dashboardSidebar(width = 150,
fluidRow(
#Filters by Region
checkboxGroupInput(inputId = "RegionInput",
label = "Region",
choices = c("Central", "East", "South", "West"), selected = c("Central", "East", "South", "West")),
#Filters by Category
checkboxGroupInput(inputId = "CategoryInput",
label = "Product Category",
choices = c("Furniture","Office Supplies", "Technology"), selected = c("Furniture","Office Supplies", "Technology")),
#filters by Sub-Category
checkboxGroupInput(inputId = "SubInput",
label = "SubCategory",
choices = c("Accessories", "Appliances","Art","Binders","Bookcases","Chairs","Copiers", "Envelopes","Fasteners" , "Furnishings",
"Labels", "Machines", "Paper" ,"Phones", "Storage", "Supplies", "Tables"),
selected = c("Accessories", "Appliances","Art","Binders","Bookcases","Chairs","Copiers", "Envelopes","Fasteners" , "Furnishings",
"Labels", "Machines", "Paper" ,"Phones", "Storage", "Supplies", "Tables")))),
# Body of the dashboard where the Charts will be plotted
dashboardBody(
fluidRow(
box( title = "Furniture is the least profitable accross all regions", status = "primary",
collapsible = TRUE, solidHeader=TRUE,
plotOutput("RegionChart"),
# infoBox("Furniture is the least profitable accross all regions",
# value = NULL, subtitle = NULL, width = 15,
# icon = shiny::icon("bar-chart")),
width = 6),
box(title = "Tables has the largest degree of negative profit", status = "primary",
collapsible = TRUE, solidHeader=TRUE,
plotOutput("SubCatChart"),
# infoBox("'Tables' has the largest degree of negative profits", width = 15),
width = 6)),
fluidRow(
box( title = "Sales Quantities do not translate into profitability" , status = "primary",
collapsible = TRUE, solidHeader=TRUE,
plotOutput("SalesQuantChart"),
# infoBox("Sales Quantities do not translate into profitability", width = 15),
width = 6),
box( title = "Discounts decrease profits and inflate sales quantities" , status = "primary",
collapsible = TRUE, solidHeader=TRUE,
plotOutput("Discounts"),
# infoBox("Discounts decrease profits and inflate sales quantities", width = 15),
width = 6)),
fluidRow(
box( title = "East region lost most on Tables" , status = "primary",
collapsible = TRUE, solidHeader=TRUE,
plotOutput("SubCatR"),
# infoBox("Sales Quantities do not translate into profitability", width = 15),
width = 6),
box( title = "High discounts decrease profits across all reagion" , status = "primary",
collapsible = TRUE, solidHeader=TRUE,
plotOutput("DiscountsR"),
# infoBox("Discounts decrease profits and inflate sales quantities", width = 15),
width = 6))
)
)
# Define server logic required to draw clustered barcharts
server <- function(input, output) {
# create calculated columns using given values from the dataset
QP2$Cost <- round(QP2$Sales - Profit,2)
QP2$DicountGiven <- round(QP2$Sales * Discount,2)
# Top Left Chart {
output$RegionChart <- renderPlot({
# Grouping data by Category and Region so it can be filtered
rc <- group_by(QP2, Region, Category) %>%
summarise(TotalProfit = sum(Profit))
# allows the data displayed in the charts to react to the Region and Product Category filters in the UI
filtered <-
rc %>%
filter(Region %in% input$RegionInput &
Category %in% input$CategoryInput)
# Clustered Bar Chart showing total profits Per Product Category by Region
ggplot(filtered, aes(x=Region, y= TotalProfit, fill = Category)) +
geom_bar(stat = "identity", position = "dodge", color = "black") +
ggtitle("Profits per Category by Region") +
labs(y="Total Profits ($)")
})
# }
# Top Right {
output$SubCatChart <- renderPlot({
# Grouping data by Category and Sub-Category so it can be filtered
scc <- group_by(.data = QP2, Sub.Category, Category) %>%
summarise(TotalProfit = sum(Profit))
# allows the data displayed in the charts to react to the Sub-Category and Product Category filters in the UI
sliced <-
scc %>%
filter( Category %in% input$CategoryInput &
Sub.Category %in% input$SubInput)
# Clustered Bar Chart showing total profits Per Sub-Category by Product Category
ggplot(sliced, aes(x=Category, y= TotalProfit, fill = Sub.Category, color = Region)) +
geom_bar(stat = "identity", position = "dodge", color = "black") +
ggtitle("Profits per Sub-Category") +
labs(y="Total Profits ($)")
})
# }
# Bottom Left Chart {
output$SalesQuantChart <- renderPlot({
# Grouping data by Category and Sub-Category so it can be filtered
sqs <- group_by(QP2,Sub.Category, Category) %>%
summarise(QuantitySold = sum(Quantity))
# allows the data displayed in the charts to react to the Sub-Category and Product Category filters in the UI
filters <-
sqs %>%
filter(
Category %in% input$CategoryInput&
Sub.Category %in% input$SubInput)
# Clustered Bar Chart showing quantity Per Sub-Category by Main Category
ggplot(filters, aes(x=Category, y= QuantitySold, fill = Sub.Category)) +
geom_bar(stat = "identity", position = "dodge", color = "black") +
ggtitle("Quantity Sold per Sub-Category") +
labs(y="Quantity Sold")
})
# }
# Bottom Right Chart {
output$Discounts <- renderPlot({
# Grouping data by Category and Sub-Category so it can be filtered
dgsc <- group_by(QP2,Sub.Category, Category) %>%
summarise(TotalDiscounts = sum(DicountGiven))
# allows the data displayed in the charts to react to the Sub-Category and Product Category filters in the UI
slices <-
dgsc %>%
filter(
Category %in% input$CategoryInput&
Sub.Category %in% input$SubInput)
# Clustered Bar Chart showing to dicounts given in dollars Per Sub-Category by Product Category
ggplot(slices, aes(x=Category, y= TotalDiscounts, fill = Sub.Category)) +
geom_bar(stat = "identity", position = "dodge", color = "black") +
ggtitle("Discounts Given per Sub-Category") +
labs(y="Total Discounts ($)")
})
# }
# Bottom Right Chart {
output$DiscountsR <- renderPlot({
# Grouping data by Category and Sub-Category so it can be filtered
dgsc <- group_by(QP2,Sub.Category, Region) %>%
summarise(TotalDiscounts = sum(DicountGiven))
# allows the data displayed in the charts to react to the Sub-Category and Product Category filters in the UI
slices <-
dgsc %>%
filter(Region %in% input$RegionInput &
# Category %in% input$CategoryInput&
Sub.Category %in% input$SubInput)
# Clustered Bar Chart showing to dicounts given in dollars Per Sub-Category by Product Category
ggplot(slices, aes(x=Region, y= TotalDiscounts, fill = Sub.Category)) +
geom_bar(stat = "identity", position = "dodge", color = "black") +
ggtitle("Discounts by region per Sub-Category") +
labs(y="Total Discounts ($)")
})
# }
# Bottom Right Chart {
output$SubCatR <- renderPlot({
# Grouping data by Category and Sub-Category so it can be filtered
dgsc <- group_by(QP2,Sub.Category, Region) %>%
summarise(TotalProfit = sum(Profit))
# allows the data displayed in the charts to react to the Sub-Category and Product Category filters in the UI
slices <-
dgsc %>%
filter(Region %in% input$RegionInput &
# Category %in% input$CategoryInput&
Sub.Category %in% c("Tables", "Bookcases", "Machines", "Fasteners"))
# Clustered Bar Chart showing to dicounts given in dollars Per Sub-Category by Product Category
ggplot(slices, aes(x=Sub.Category, y= TotalProfit, fill = Region)) +
geom_bar(stat = "identity", position = "dodge", color = "black") +
ggtitle("Profit by Region per problematic Sub-Category") +
labs(y="Total Profit ($)")
})
# }
}
# Run the application
shinyApp(ui = ui, server = server)