Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# load this package to use HTTP verbs
postcode_lookup <- function(postcode) {
r <- GET(paste0("", postcode))
# returns a list
pc_content <- postcode_lookup("EC1Y 8LX")
# transform into a data frame
pc_result <- pc_content[[2]]
take_names <- setdiff(names(pc_result), 'codes')
pc_result[sapply(pc_result, is.null)] = list(NA)
pc_df <- cbind([take_names]),$codes))
# create an interactive map
library(dplyr) # load pipes
library(leaflet) # load maps
leaflet(pc_df) %>%
addTiles() %>%
addCircles(lng = ~longitude, lat = ~latitude, popup = ~postcode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment