---
title: "Flex Dashboards"
Author : Dhela Asafiani Agatha (20214920009)
output:
flexdashboard::flex_dashboard:
vertical_layout: scroll
theme: yeti
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(highcharter)
library(gtable)
library(htmltools)
library(viridis)
library(DT)
library(flexdashboard)
library(shiny)
# From Github
#install.packages("devtools")
#devtools::install_github("dreamRs/shinyWidgets")
library(shinyWidgets)
library(shinyjs)
```
```{r}
# Importing data
library(dplyr)
library(plotly)
library(tidyverse)
df <- read.csv('sales_data_sample.csv')
# Removing duplicates
df <- df %>%
distinct(COUNTRY, .keep_all = TRUE) %>%
rename(Country = 'COUNTRY')
```
Table {data-orientation=rows}
=======================================================================
### Table {data-height=520}
```{r}
# This is going to be a datatable
df1 <- df %>%
filter(Country >= 5 ) %>%
arrange(desc(ORDERDATE)) %>%
select(Country, QUANTITYORDERED,STATUS, SALES, YEAR_ID, ORDERDATE)
datatable(df1,
options=list(scrollX=TRUE),
caption = htmltools::tags$caption(
style = 'caption-side: bottom; text-align: center;',
'', htmltools::em('')
))
```
Bar-chart {data-orientation=rows}
=======================================================================
## Column {.tabset .tabset-fade data-height=520}
-----------------------------------------------------------------------
```{r fig.height=5}
# Colors
custom_colors <- viridis::turbo(n = 15)
# Most popular authors by reviews
df %>%
group_by(Country) %>%
summarise(SALES = sum(SALES)) %>%
arrange(desc(SALES)) %>%
head(15) %>%
hchart('column', hcaes(x = Country, y = SALES,color = custom_colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Reviews: </b> {point.y} <br>') %>%
hc_title(text = 'Top Sales in Many Country',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'By Number of Reviews',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@dhelaagatha')
```
Donut-chart {data-orientation=rows}
=======================================================================
## Row
-----------------------------------------------------------------------
```{r fig.height=5}
data1 <- read.csv('sales_data_sample.csv')
# Colors
custom_colors <- viridis::inferno(n = 7)
# Most popular artists by weeks on board
data1 %>%
group_by(PRODUCTLINE) %>%
summarise(QUANTITYORDERED = sum(QUANTITYORDERED)) %>%
arrange(desc(QUANTITYORDERED)) %>%
head(10) %>%
hchart('pie', hcaes(x = PRODUCTLINE, y = QUANTITYORDERED, color = custom_colors),innerSize = 200) %>%
hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Weeks on Board: </b> {point.y} <br>') %>%
hc_title(text = 'MOST POPULAR PRODUCTLINE',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'By Number of QUANTITYORDERED',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@dhelaagatha')
```
Bar-chart {data-orientation=rows}
=======================================================================
## Column {.tabset .tabset-fade data-height=520}
-----------------------------------------------------------------------
```{r}
df %>%
count(TERRITORY) %>%
mutate(TERRITORY = fct_reorder(TERRITORY, n)) %>%
plot_ly(x = ~TERRITORY, y = ~n, color = ~TERRITORY, type = "bar") %>%
layout(title = 'Frequency of Sales from its Territory',
xaxis = list(showgrid = FALSE),
yaxis = list(title = 'Frequency',showgrid = FALSE),
showlegend = FALSE)
```
Line-chart {data-orientation=rows}
=======================================================================
## Column {.tabset .tabset-fade data-height=520}
-----------------------------------------------------------------------
```{r}
df2 <- df %>%
distinct(YEAR_ID, .keep_all = TRUE) %>%
rename(YEAR_ID = 'YEAR_ID')
fig <- plot_ly(df2, x = ~YEAR_ID, y = ~QUANTITYORDERED,color= ~QUANTITYORDERED, name = "Gaps", type = 'scatter', mode = 'lines') %>%
layout(title = 'TOTAL QUANTITY ORDERED BY YEAR',
xaxis = list(showgrid = FALSE),
yaxis = list(title = 'Quantity Ordered',showgrid = FALSE),
showlegend = FALSE)
fig
```