-
Notifications
You must be signed in to change notification settings - Fork 0
/
adidas_dataoverview.R
93 lines (48 loc) · 2.52 KB
/
adidas_dataoverview.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
adidas_dataoverview_UI <- function(id) {
ns <- NS(id)
tagList(
fluidRow(
box(title="Data Overview", status = "primary", width=12, dataTableOutput(ns("dataoverview")))
),
fluidRow(
box(title= "Quick Analysis", status = "primary", width=12,
column(width=4,selectizeInput(ns('category'), label="Choose the Determinant for your Quick Analysis", choices = c("Retailer", "Product", "Region"), multiple = FALSE)))
),
fluidRow(
box(title = "Result of your Quick Analysis (in Mio $)", status = "primary", width = 6, dataTableOutput(ns("datafiltered"))),
box(title = "Visualisation of your Quick Analysis (in Mio $)", status = "primary", width = 6, plotlyOutput(ns("datavisualisation")))
)
)
}
adidas_dataoverview <- function(input, output, session) {
# Overview ----------------------------------------------------
#Creating a Datatable which shows selected columns of the Raw Data
output$dataoverview <- renderDataTable({
temp <- adidas %>%
select(Retailer, `Invoice Date`, City, Product, `Units Sold`, `Total Sales`, `Operating Margin`)
DT::datatable(temp, filter='bottom', options=list(pageLength=10))
})
# Quick Analysis ----------------------------------------------
#Data Preparation: Grouping the data based on the chosen category (Retailer, Product or Region) and summarizing Revenue and Profit.
datafiltered_input <- reactive({
temp <- adidas%>%
group_by_at(input$category) %>%
summarize(Profit = round(sum(`Operating Profit`)/1000000,2), Revenue = round(sum(`Total Sales`)/1000000,2)) %>%
ungroup()
temp <- temp %>% mutate(Margin = round(Profit/Revenue,2))
return(temp)
})
#Data Table: Visualizing a data table based on the prepared data
output$datafiltered <- renderDataTable({
temp <- datafiltered_input()
DT::datatable(temp, filter='bottom', options=list(pageLength=6))
})
#Visualization: Visualizing the prepared data in a bar chart
output$datavisualisation <- renderPlotly({
temp <- datafiltered_input()
plot_ly(data = temp, x = ~get(input$category)) %>%
add_trace(y=~Revenue, type ='bar', name = "Revenue") %>%
add_trace(y=~Profit, type = "bar", name = "Profit") %>%
layout(xaxis = list(title = ""), yaxis = list(title = ""), showlegend = TRUE)
})
}