Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Leaflet and Alteryx - Passing Spatial fields to R Tool

rborger
7 - Meteor

Good afternoon all,

 

I'm looking to utilize Alteryx to create leaflet maps using the R Tool. This was very straightforward when using lat/long points to create pins, but when trying to do the same for polygons, there is an object class discrepancy between what leaflet is looking for and what Alteryx passes the R tool.

 

Super simple use case as an example: Map 1 Block Group polygon from Alteryx on a Leaflet HTML map. Using the Allocate Input tool, I generated a SpatialObj for the below block group, and trimmed fields so the below data table is our "#1" input to R.

 

GEOIDSpatialObj
040159548002Polygon
 
Here is the R code to plot this polygon in a leaflet map:

 

 

library(leaflet)

blockgroup <- read.Alteryx("#1", mode = "list")

map <- leaflet() %>%
  addTiles() %>%
  addPolygons(data = blockgroup$SpatialObj,
              fillOpacity = 0.7,
              weight = 1, 
              smoothFactor = 0.2,
              fillColor = "green",
              color = "green"
              )

 

 

 

When executing the above code, I am presented with the following error: Error: R (1): Error in polygonData.default(data) :Info: R (1): Don't know how to get path data from object of class list

Any advice for how to resolve this error would be greatly appreciated!

1 REPLY 1
rborger
7 - Meteor

In case anyone happens upon this in search of a solution, I came up with 2 methods (there may be better ones):

 

1. Pass GEOID from Alteryx to R Tool and use tigris package to merge geometry by GEOID

2. Pass lat/longs for the extent of polygon from Alteryx to R Tool and use sf package to draw polygon from series of lat/longs

Labels