# Specify username and observations URL
username <- "shmuir"
url <- paste0 ("https://api.inaturalist.org/v1/observations?user_id=" , username, "&per_page=200" )
# Make the GET request
response <- GET (url)
# Parse the JSON content
data <- content (response, as = "text" , encoding = "UTF-8" )
json_data <- fromJSON (data, flatten = TRUE )
# Convert json data to data frame
observations <- as.data.frame (json_data$ results)
# Extract latitude and longitude from 'location' column
observations <- observations %>%
mutate (lat = as.numeric (sapply (strsplit (location, "," ), ` [ ` , 1 )),
lng = as.numeric (sapply (strsplit (location, "," ), ` [ ` , 2 ))) %>%
select (species_guess, observed_on, location, lat, lng, taxon.iconic_taxon_name, taxon.default_photo.square_url, taxon.name, taxon.preferred_common_name) %>%
mutate (taxon.preferred_common_name = str_to_title (taxon.preferred_common_name))
## CURRENTY DOES NOT WORK
# icoLst <- awesomeIconList(
# Plantae = makeAwesomeIcon(text = fa("seedling"), library = "fa", markerColor = "white"),
# Insecta = makeAwesomeIcon(text = fa("mosquito"), library = "fa", markerColor = "white"),
# Mammalia = makeAwesomeIcon(text = fa("paw"), library = "fa", markerColor = "white"),
# Animalia = makeAwesomeIcon(text = fa("shield-cat"), library = "fa", markerColor = "white"),
# Aves = makeAwesomeIcon(text = fa("crow"), library = "fa", markerColor = "white"),
# Reptilia = makeAwesomeIcon(text = fa("worm"), library = "fa", markerColor = "white"),
# Mollusca = makeAwesomeIcon(text = fa("disease"), library = "fa", markerColor = "white"),
# Fungi = makeAwesomeIcon(text = fa("bacterium"), library = "fa", markerColor = "white"),
# Unknown = makeAwesomeIcon(text = fa("question-circle"), library = "fa", markerColor = "gray"),
# Chromista = makeAwesomeIcon(icon = fa("disease"), library = "fa", markerColor = "white"),
# Actinopterygii = makeAwesomeIcon(icon = fa("fish"), library = "fa", markerColor = "white")
# )
# Create Leaflet map with markers and icons
leaflet (observations) %>%
addTiles () %>%
addAwesomeMarkers (
lng = ~ lng, lat = ~ lat,
# icon = ~icoLst[taxon.iconic_taxon_name],
popup = ~ paste ("Species: " , taxon.preferred_common_name, "<br>" ,
"Scientific Name: " , taxon.name, "<br>" ,
"Date: " , observed_on, "<br>" ,
"Type: " , taxon.iconic_taxon_name, "<br>" ,
"Location: " , location,
"<br><img src='" , taxon.default_photo.square_url, "' alt='Species Image' style='width:50px;height:50px;'>" ),
clusterOptions = markerClusterOptions ()
) %>%
addScaleBar (position = "bottomleft" ) %>%
addMiniMap (position = "bottomright" , width = 100 , height = 100 )