---
title: "Processサンプル（リピート率のモニタリング）"
output: 
  flexdashboard::flex_dashboard:
    orientation: "row"
---

```{r setup, include=FALSE}
library(flexdashboard)
library(plotly)
library(dplyr)

data <- read.csv("./data/process.csv") %>%
  filter(year == "2016") %>%
  group_by(month) %>%
  summarise(newCustomers      = n(),
            repeats           = sum(repeats),
            repeats.rate      = 100 * sum(repeats) / n(),
            repeats.rate.goal = 45)
```

row {data-height=20%}
----

### card1

```{r}
valueBox(paste(sum(data$newCustomers), "人"),
         caption = "累計新規顧客数")
```

### card2

```{r}
valueBox(paste(sum(data$repeats), "人"), 
         caption = "累計新規顧客のリピート数")
```

### card3

```{r}
valueBox(paste(round(100 * sum(data$repeats) /sum(data$newCustomers), 0), "%"),
         caption = "累計リピート率")
```

row {data-height=40%}
----

### 顧客数の推移

```{r}
plot_ly(data, x = ~month, y = ~newCustomers, name = '新規顧客数', type = 'scatter', mode = 'lines+markers') %>%
  add_trace(y = ~repeats, name = 'リピータ数', mode = 'lines+markers') %>%
  layout(xaxis = list(title = "月"), yaxis = list(title = ""))
```


row {data-height=40%}
----

### リピート率の推移

```{r}
plot_ly(data, x = ~month, y = ~repeats.rate.goal, name = '目標', type = 'scatter', mode = 'lines') %>%
  add_trace(y = ~repeats.rate, name = 'リピート率', mode = 'lines+markers') %>%
  layout(xaxis = list(title = "月"), yaxis = list(title = ""))
```