---
title: "Factory_DB Dashboard"
output:
flexdashboard::flex_dashboard:
vertical_layout: scroll
theme: united
source_code: embed
---
```{r setup, include=FALSE}
# Importing libraries
library(flexdashboard)
library(tidyverse)
library(highcharter)
library(gt)
library(htmltools)
library(viridis)
library(DT)
```
```{r, include = FALSE}
# Importing data
orders<- read.csv('Orders.csv')
product = read.csv('Products.csv')
employee = read.csv('Employees.csv')
Cust = read.csv('Customers.csv')
ship = read.csv('Shippers.csv')
orderdets = read.csv('OrderDetails.csv')
supp = read.csv('Suppliers.csv')
cat = read.csv('Categories.csv')
```
Revenue Dashboard {data-orientation=columns}
=======================================================================
## Row
-----------------------------------------------------------------------
### Sales By Country {data-width=1440}
```{r, include = FALSE}
df2 <- merge(x=orders,y=orderdets,
by="OrderID")
df2a = merge(df2, Cust, by='CustomerID')
df2b = merge(df2a, product, by='ProductID')
df2b$TotalOrder = df2b$Quantity*df2b$Price
```
```{r}
# Colors
custom_colors <- viridis::plasma(n = 21)
df2b %>%
group_by(Country) %>%
summarise(TotalOrder= sum(TotalOrder)) %>%
arrange(desc(TotalOrder)) %>%
head(21) %>%
hchart('column', hcaes(x = Country, y =TotalOrder ,color = custom_colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Sales: </b> {point.y} <br>') %>%
hc_title(text = 'Total Sales by Country',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'Sort By Descending',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
### Sales Movement {data-width=1440}
```{r}
df2b$OrderDate = as.Date(df2b$OrderDate)
colors <- viridis::magma(n = 8)
library(tidyverse)
#group data by month and sum sales
df2b %>%
group_by(month = lubridate::floor_date(OrderDate, 'month')) %>%
summarize(TotalRevenue = sum(TotalOrder)) %>%
head(8) %>%
hchart('line', hcaes(x = month, y =TotalRevenue ,color = colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Sales: </b> {point.y} <br>') %>%
hc_title(text = 'Total Sales by Month',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'Visualized in A Line',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
Products Dashboard {data-orientation=columns}
=======================================================================
## Row
-----------------------------------------------------------------------
### Top 10 Product Sold By Quantity
```{r}
# Colors
custom_colors <- viridis::plasma(n = 10)
df2b %>%
group_by(ProductName) %>%
summarise(ProductQuantity= sum(Quantity)) %>%
arrange(desc(ProductQuantity)) %>%
head(10) %>%
hchart('lollipop', hcaes(x = ProductName, y =ProductQuantity ,color = custom_colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Quantity: </b> {point.y} <br>') %>%
hc_title(text = 'Total Sales by Product',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = '10 Most Sold Product By Quantity',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
### Top 10 Product made the most Revenue {data-width=800}
```{r}
color1 <- viridis::inferno(n = 10)
df2b %>%
group_by(ProductName) %>%
summarise(TotalOrder= sum(TotalOrder)) %>%
arrange(desc(TotalOrder)) %>%
head(10) %>%
hchart('column', hcaes(x = ProductName, y =TotalOrder ,color = color1)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Sales: </b> {point.y} <br>') %>%
hc_title(text = 'Total Sales of Product',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'Top 10 By revenue',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
### Category
```{r}
# Load required R packages
library(tidyverse)
library(highcharter)
df2c = merge(df2b, cat, 'CategoryID')
df2c%>%
group_by(CategoryName) %>%
summarise(TotalOrder= sum(TotalOrder)) %>%
arrange(desc(TotalOrder)) %>%
head(8) %>%
hchart(
"treemap",
hcaes(x = CategoryName, value = TotalOrder, color = TotalOrder)
) %>% hc_add_theme(hc_theme_google()) %>%
hc_colorAxis(stops = color_stops(colors = viridis::inferno(10))) %>%
hc_tooltip(pointFormat = '<b>Number of Sales: </b> {point.value} <br>') %>%
hc_title(text = 'Total Sales by Categories',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'By Treemap Proportions',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
### Products Price Scatter plot
```{r, include=FALSE}
dfx = df2c%>%
group_by(ProductName) %>%
summarise(price= (Price), TotalOrder=sum(TotalOrder), TotalQ = sum(Quantity), category =(CategoryName)) %>%
arrange(desc(price))
dfxx = dfx %>%
distinct(ProductName, .keep_all = TRUE)
```
```{r}
custom = viridis::viridis(n=77)
dfxx %>%
hchart('scatter', hcaes(x = TotalOrder, y =TotalQ , size = price, group = ProductName)) %>% hc_colors(custom) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Price Each: </b> {point.price} <br> <b>Total Sales : </b> <br> {point.x} <br> <b>Quantity Sold : </b> <br> {point.y}') %>%
hc_title(text = 'Total Sales by Quantity and Price Each',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'Visualized in Scatter',
style = list(fontSize = '16px')) %>%
hc_legend(enabled=F) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
Human Resource Dashboard {data-orientation=columns}
=======================================================================
## Row
-----------------------------------------------------------------------
### Employees Work rate {data-width=1500}
```{r}
# Colors
custom <- rainbow(n = 9)
df2d = merge(df2b, employee, 'EmployeeID')
df2d%>%
group_by(FirstName, quarter = lubridate::floor_date(OrderDate, 'quarter')) %>%
summarise(TotalOrder= sum(TotalOrder)) %>%
arrange(FirstName) %>%
hchart('line', hcaes(x = quarter, y =TotalOrder , group = FirstName)) %>% hc_colors(custom) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Sales: </b> {point.y} <br>') %>%
hc_title(text = 'Total Sales by Quarter Per Employyee',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'Visualized in A Line',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
### Average Order Total of Each Employees
```{r}
df2d %>%
group_by(FirstName) %>%
summarise(TotalOrder= mean(TotalOrder)) %>%
arrange(desc(TotalOrder)) %>%
hchart('lollipop', hcaes(x = FirstName, y =TotalOrder ,color = custom)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b> Average Order Amount: </b> {point.y} <br>') %>%
hc_title(text = 'Average Orders Per Employees ',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'Sort from the highest average',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
###
```{r}
df2e = merge(df2d, cat, 'CategoryID')
color2 <- viridis::turbo(n = 8)
df2e %>%
group_by(FirstName, CategoryName) %>%
summarise(TotalOrder= sum(TotalOrder) )%>%
arrange(desc(TotalOrder)) %>%
hchart('column', hcaes(x = FirstName, y =TotalOrder ,group = CategoryName), stacking='normal') %>% hc_colors(color2) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b> Revenue from This Category : </b> {point.y} <br>') %>%
hc_title(text = 'Employees Revenue ',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'Classified per Categories',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
Supplier Dashboard {data-orientation=columns}
=======================================================================
## Row
-----------------------------------------------------------------------
### Suppliers and Number of Product which they were supplying {data-width=1500}
```{r}
colors <- viridis::plasma(n=29)
df2f = merge(df2e, supp, 'SupplierID')
df2f %>%
group_by(SupplierName) %>%
summarise(Products= n_distinct(ProductName)) %>%
arrange(desc(Products)) %>%
hchart('column', hcaes(x = SupplierName, y =Products ,color = colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Products Supplied: </b> {point.y} <br>') %>%
hc_title(text = 'Total products Supplied',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'From Each Supplier',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```
### Which Suupliers gave us the highest revenue ??
```{r}
colors <- viridis::viridis(n = 29)
df2f %>%
group_by(SupplierName) %>%
summarise(Revenue = sum(TotalOrder)) %>%
arrange(desc(Revenue)) %>%
hchart('bar', hcaes(x = SupplierName, y = Revenue,color = colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Revenue From This Supplier: </b> {point.y} <br>') %>%
hc_title(text = 'Total Revenue Gained',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'From Each Supplier',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@stroberi')
```