branch <- params$branch

statement <- glue::glue_sql("SELECT * from customers
                             WHERE branch == {branch}", 
                            .con = db)

mydata <- DBI::dbGetQuery(conn = db,
                          statement = statement) %>% 
  dplyr::arrange(desc(interest_income))

Top Customers by State

final_kable  <- mydata %>% 

  dplyr::select(CIF, Customer = cust_name, `Interest Income` = interest_income) %>%
  dplyr::mutate('Interest Income' = scales::dollar(`Interest Income`)) %>% 

  knitr::kable("latex", booktabs = T, longtable = T, align = c("l","r", "r")) %>%

  kableExtra::kable_styling(
    latex_options = c("scale_down"),
    position = "left", full_width = T
  )  %>% 
 kableExtra::kable_styling(font_size = 12) 


final_kable
# now for a map

# get state data
states <- sf::st_as_sf(maps::map("state", plot = FALSE, fill = TRUE))

# combine 
final <- mydata %>% 
  dplyr::left_join(states, by = c("state" = "ID"))

Top Customers by State - Total Interest Income

ggplot() +
  geom_sf(data = final$geom, aes(fill = final$interest_income)) +
  scale_fill_viridis_c(trans = "sqrt", alpha = .7) +
  labs(fill='Interest Income') + 
  theme_void()


lindblb/pro_reports_talk documentation built on Jan. 1, 2021, 8:21 a.m.