---
title: "Students' Favorite Cafes"
author: "Dr. Richard M. Crowley"
date: "ACCT 101, Fall 2021"
output:
  html_document:
    highlight: default
    self_contained: yes
    theme: spacelab
    toc: yes
    toc_float:
      collapsed: no
  pdf_document:
    toc: no
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

### Chart of cafes

```{r, echo=FALSE, message=F, warning=F}
library(tidyverse)
library(magrittr)
df <- read.csv("../Data/About you-Edit.csv", stringsAsFactors=FALSE) %>%
  rename(country_name=Where.did.you.grow.up...country.or.region.,
         cafe=What.is.your.favorite.cafe..coffee.shop..tea.shop..etc....N.A.if.you.don.t.have.one.)
ll <- read_tsv("../Data/countries_latlon.csv") %>%
  rename(country_name=name)
df %<>% left_join(ll)

library(leaflet)

df_cafe <- readRDS("google_maps_query.rds")

df %>% left_join(df_cafe) %>%
  filter(!is.na(place_id)) %>%
  leaflet() %>%
  setView(lng = 103.8498277, lat = 1.2956192, zoom = 14) %>%
  addTiles() %>%
  addMarkers(lng = ~long, lat = ~lat, clusterOptions = markerClusterOptions(),
             label = ~paste0(cafe_name),
             popup = ~paste0('<div style="font-size:18px; padding:10px; line-height:20px">Query: ',cafe,
                             '<br><a href="https://www.google.com/maps/search/?api=1&query=Google&query_place_id=',place_id,'">Link on Gmaps</a>',
                             '<br>Rating on Gmaps: ',rating,
                             '<br>Address: ',address,'</div>'))
```

### Methodology

The above chart is based on a class survey crossed with Google's Places API.  Google doesn't always get it right, and thus not everything above is correct.  Hover to see the name of the cafe, and click to see the queried name, as well as the address, rating, and a Google Maps link for each cafe.