file <- "yelp_academic_dataset_business.json"
business <- jsonlite::stream_in(textConnection(readLines(file, n=300000)), flatten = TRUE)
head_business = head(business, 20)
datatable(head_business[,1:12],
options = list(
pageLength = 5,
scrollX = TRUE,
autoWidth = TRUE
),
class = 'cell-border stripe'
)
state_counts <- business %>%
group_by(state) %>%
summarise(count = n())
fig <- plot_ly(data=state_counts, labels=~state_counts$state, values=~state_counts$count, type = 'pie')%>%
layout(title=list(text = "% Negócios por Estado Americano"),
legend=list(title=list(text='Estados')))
fig
### this function will color each location based on the star rating it has
coffeeStores <- business # %>% filter(str_detect(str_to_lower(categories), str_to_lower("Coffee")))
colors <- colorFactor(c("purple", "red", "orange", "black","blue"),
domain = unique(coffeeStores$stars))
### this draws the map
map <- leaflet(coffeeStores, width = "100%") %>%
addProviderTiles("CartoDB.Positron") %>%
addCircleMarkers(
color = ~colors(coffeeStores$stars),
stroke = FALSE, fillOpacity = 0.5,
lat = coffeeStores$latitude,
lng = coffeeStores$longitude,
clusterOptions = markerClusterOptions(),
popup = as.character(head_business$name))
map