---
title: "Pertemuan 12 Flexdashboard"
output:
flexdashboard::flex_dashboard:
vertical_layout: scroll
source_code : embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(plotly)
library(ggplot2)
library(tidyverse)
library(highcharter)
library(gtable)
library(htmltools)
library(viridis)
library(DT)
```
```{r}
# Importing data
bank <- read_csv('Bank Customer Churn Prediction.csv')
# Removing duplicates
bank <- bank %>%
distinct(customer_id, .keep_all = TRUE) %>%
rename(account_balance = 'balance')
```
Data Bank ABC {data-orientation=rows}
=======================================================================
### Table {data-height=520}
```{r}
# This is going to be a datatable
bank1 <- bank %>%
filter(account_balance > 0, age < 25) %>%
arrange(desc(customer_id)) %>%
select(customer_id, credit_score, country, gender, age, tenure, account_balance, products_number, credit_card)
datatable(bank1,
options=list(scrollX=TRUE),
caption = htmltools::tags$caption(
style = 'caption-side: bottom; text-align: center;',
'Table: ', htmltools::em('Bank Customer Churn Prediction by account_balance more than 0')
))
```
Bar-chart {data-orientation=rows}
=======================================================================
```{r fig.height=5}
# Colors
custom_colors <- viridis::turbo(n = 3)
# Most Rich Country of Bank Customer by Number of Account Balance
bank1 %>%
group_by(country) %>%
summarise(account_balance = sum(account_balance)) %>%
arrange(desc(account_balance)) %>%
head(15) %>%
hchart('column', hcaes(x = country, y = account_balance,color = custom_colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Account Balance: </b> {point.y} <br>') %>%
hc_title(text = 'Negara Terkaya di Bank ABC',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'berdasarkan jumlah saldo customer tiap negara',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = 'sausanramadhani')
```
Donut-chart {data-orientation=rows}
=======================================================================
```{r fig.height=5}
# Colors
custom_colors <- viridis::inferno(n = 10)
# Many loyal customer by tenure
bank1 %>%
group_by(tenure) %>%
summarise(customer_id = sum(customer_id)) %>%
arrange(desc(customer_id)) %>%
head(10) %>%
hchart('pie', hcaes(x = tenure, y = customer_id, color = custom_colors),innerSize = 200) %>%
hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of tenure: </b> {point.y} <br>') %>%
hc_title(text = 'Banyaknya Pelanggan Setia',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'berdasarkan lamanya berlangganan',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = 'sausanramadhani')
```