Skip to content

Instantly share code, notes, and snippets.

Created January 2, 2020 16:13
Show Gist options
  • Save kellobri/8c36e68fe7924b420b95d60fe0ffd19b to your computer and use it in GitHub Desktop.
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
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`
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}
title: "Cookie Cutter Shop Report"
- cookie-shop-banner.png
- low-inventory-banner.png
output: html_document
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
## 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}
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}
orders <- cookie_shop_orders %>%
select(purple, black, red, total_orders) %>%
#### 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}
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()
Copy link

Hi, where's your inventory_levels object, and how do the inventory-alert and inventory-update files know where to look for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment