-
Notifications
You must be signed in to change notification settings - Fork 0
/
revenue_shiny.R
109 lines (93 loc) · 3.22 KB
/
revenue_shiny.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
library(shiny)
library(shinydashboard)
library(ggplot2)
library(dplyr)
recommendation <- read.csv('recommendation.csv', stringsAsFactors = FALSE, header = TRUE)
head(recommendation)
#Dashboard header carrying the title of the dashboard
header <- dashboardHeader(title = "Basic Dashboard")
#Sidebar content of the dashboard
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Visit-us", icon = icon("send", lib = 'glyphicon'),
href = "http://www.suebayes.com")
)
)
frow1 <- fluidRow(
valueBoxOutput("value1"),
valueBoxOutput("value2"),
valueBoxOutput("value3")
)
frow2 <- fluidRow(
box(
title = "Revenue per Account",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("revenuebyPrd", height = "300px")
),
box(
title = "Revenue per Product",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("revenuebyRegion", height = "300px")
)
)
body <- dashboardBody(frow1, frow2)
ui <- dashboardPage(
title = "Sue Bayes Dashboard Example", header, sidebar, body, skin = "red")
#create the server functions for the dashboard
server <- function(input, output) {
#some data manipulation to dervie the values of the KPI boxes
total.revenue <- sum(recommendation$Revenue)
sales.account <- recommendation %>%
group_by(Account) %>%
summarise(value = sum(Revenue)) %>%
filter(value == max(value))
prof.prod <- recommendation %>% group_by(Product) %>%
summarise(value = sum(Revenue)) %>%
filter(value==max(value))
#creating the valueBoxOutput content
output$value1 <- renderValueBox({
valueBox(
formatC(sales.account$value, format="d", big.mark = ','),
paste('Top Account: ', sales.account$Account),
icon = icon("stats", lib = 'glyphicon'),
color = 'purple')
})
output$value2 <- renderValueBox({
valueBox(
formatC(total.revenue, format="d", big.mark = ','),
paste('Top Expected Revenue '),
icon = icon("stats", lib = 'glyphicon'),
color = 'green')
})
output$value3 <- renderValueBox({
valueBox(
formatC(prof.prod$value, format="d", big.mark = ','),
paste('Top Product: ', prof.prod$Product),
icon = icon("stats", lib = 'glyphicon'),
color = 'yellow')
})
#creating the plotOutput content
output$revenuebyPrd <- renderPlot({
ggplot(data = recommendation,
aes(x=Product, y=Revenue, fill=factor(Region))) +
geom_bar(position = "dodge", stat = "identity") +
ylab("Revenue (in £s)") +
xlab("Product") + theme(legend.position="bottom"
,plot.title = element_text(size=15, face="bold")) +
ggtitle("Revenue by Product") + labs(fill = "Region")
})
output$revenuebyRegion <- renderPlot({
ggplot(data = recommendation,
aes(x=Account, y=Revenue, fill=factor(Region))) +
geom_bar(position = "dodge", stat = "identity") + ylab("Revenue (in Euros)") +
xlab("Account") + theme(legend.position="bottom"
,plot.title = element_text(size=15, face="bold")) +
ggtitle("Revenue by Region") + labs(fill = "Region")
})
}
shinyApp(ui, server)