0

I'm trying to publish a map on Shiny, but keep running into this issue.

Let's call the data.frame region. Here are the columns:

  library(mapedit)
  library(mapview)
  library(shiny)
  library(leaflet)
  library(leaflet.extras)   



  region$address
  region$city
  region$state
  region$zip
  region$county
  region$xcol (these are the longitude coordinates)
  region$ycol (these are the latitude coordinates)

But when I run the mapview(region)@map it produces the following error:

Error: oops! Arguments xcol and/or ycol are missing! You probably expected turf_clean to be a spatial object. However it is of class data.frame. Either convert turf_clean to a spatial object or provide xcol and ycol.

I provided the x and y cols, but it's still not producing what I need.

1 Answers1

0

The library sf and its st_as_sf() is a way to convert your data.frame to a spatial object. crs refers to the datum and projection, which I just guessed assuming your lat/long are relative to the WGS84 datum. I believe the projection is what maps.google.com uses - web mercator auxiliary sphere.

library(sf)
turf_clean <- st_as_sf(region, coords = c("xcol", "ycol"), crs = 4326) 
dbo
  • 1,174
  • 1
  • 11
  • 19
  • What exactly is `crs`? What does that mean? –  Aug 21 '19 at 16:58
  • @gooponyagrinch it means coordinate reference system. There may be better sites but a quick google returned this https://rspatial.org/spatial/6-crs.html?highlight=coordinate%20reference%20system – dbo Aug 21 '19 at 17:14