Created
January 2, 2020 16:13
-
-
Save kellobri/8c36e68fe7924b420b95d60fe0ffd19b to your computer and use it in GitHub Desktop.
Conditional Either/Or Example: Etsy Shop R Markdown Report with Blastula Custom Email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Action Required: Low Inventory Alert!" | |
output: blastula::blastula_email | |
--- | |
<img src="low-inventory-banner.png"> | |
A low inventory alert has been triggered - Review the current inventory levels below to determine which filament colors need to be replenished today. | |
### Current inventory by unit color: | |
- **Purple:** `r inventory_levels$p_inventory` | |
- **Black:** `r inventory_levels$b_inventory` | |
- **Red:** `r inventory_levels$r_inventory` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Orders and Inventory Update" | |
output: blastula::blastula_email | |
--- | |
<img src="cookie-shop-banner.png"> | |
## Orders and Inventory Update | |
### Running Shop Totals | |
- **Orders:** `r orders$total_orders` | |
- **Total units sold:** `r orders$purple + orders$black + orders$red` | |
### Remaining Inventory | |
- **Purple filament:** `r inventory_levels$p_inventory` | |
- **Black filament:** `r inventory_levels$b_inventory` | |
- **Red filament:** `r inventory_levels$r_inventory` | |
```{r orders_inventory, echo=FALSE, message=FALSE, warning=FALSE} | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Cookie Cutter Shop Report" | |
resource_files: | |
- cookie-shop-banner.png | |
- low-inventory-banner.png | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
library(blastula) | |
``` | |
## Orders, Sales, and Inventory Level | |
This is an example report based loosely on a real Etsy shop I once experimented with running. All data is simulated. | |
Import data from CSV: | |
```{r import_data, message=FALSE, warning=FALSE} | |
library(readr) | |
cookie_shop_orders <- read_csv("cookie-shop-inventory.csv", | |
col_types = cols(date = col_date(format = "%m/%d/%y"))) | |
``` | |
Summarize the orders data for each filament type: | |
```{r sales_tracker, message=FALSE, warning=FALSE} | |
library(dplyr) | |
orders <- cookie_shop_orders %>% | |
select(purple, black, red, total_orders) %>% | |
summarise_all(sum) | |
``` | |
#### Running count of total shop orders placed: `r orders$total_orders` | |
### Count of units ordered by color: | |
- **Purple:** `r orders$purple` | |
- **Black:** `r orders$black` | |
- **Red:** `r orders$red` | |
#### Total units sold: `r orders$purple + orders$black + orders$red` | |
--- | |
## Inventory Burndown Charts | |
### Filament color orders and inventory level: | |
```{r orders_inventory, echo=FALSE, , message=FALSE, warning=FALSE} | |
library(ggplot2) | |
library(ggthemes) | |
library(gridExtra) | |
p <- cookie_shop_orders %>% | |
ggplot() + geom_bar(aes(x = date, y = purple), stat = "identity", color="purple", fill="white") + | |
geom_line(aes(x = date, y = p_inventory)) + theme_clean() | |
b <- cookie_shop_orders %>% | |
ggplot() + geom_bar(aes(x = date, y = black), stat = "identity", color="black", fill="white") + | |
geom_line(aes(x = date, y = b_inventory)) + theme_clean() | |
r <- cookie_shop_orders %>% | |
ggplot() + geom_bar(aes(x = date, y = red), stat = "identity", color="red", fill="white") + | |
geom_line(aes(x = date, y = r_inventory)) + theme_clean() | |
grid.arrange(p,b,r) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, where's your
inventory_levels
object, and how do the inventory-alert and inventory-update files know where to look for it?