Skip to content

Instantly share code, notes, and snippets.

@ilantoren
Created July 20, 2021 14:21
Show Gist options
  • Save ilantoren/45affaa556f7ab8bbc850cebcd674769 to your computer and use it in GitHub Desktop.
Save ilantoren/45affaa556f7ab8bbc850cebcd674769 to your computer and use it in GitHub Desktop.
Mongo Loves Data - Using the map-region.py code to create a map
library( reticulate)
library(ggplot2)
library( dplyr )
# As in the call-python.R script the structure remains unchanged
# A) load the python file
# B) use the function to return a data.frame
# i) name is the neighborhood name
# ii) restaurants
# iii) region_lng and region_at
# iv) long and lat for the restaurant markers: R and python don't play nicely enough together to make it worth the effort to extract this from data$restaurant['address']
#
use_python('/usr/local/bin/python3')
source_python( 'map-region.py')
data <- get_data('Middle Village')
LONG = median( data$long )
LAT = median( data$lat )
# Build the basic graph
m <- leaflet() %>%
addTiles() %>%
setView(LONG, LAT, zoom = 13)
#add polygon and individual markers
m %>% addPolygons( lng= data$region_lng, lat = data$region_lat, fillColor='yellow', color='red', stroke=TRUE, opacity=0.5, label="Middle Village", ) %>%
addMarkers(d, lng=data$long, lat = data$lat, popup = data$restaurants['name'] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment