-
Notifications
You must be signed in to change notification settings - Fork 506
Leaflet returns an error for empty "sf" "dataframe" objects #452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Are you sure this error is generated by leaflet? I think this is an error message from sf. |
Could well be. There's an issue here from sf for handling empty data frames for plot - r-spatial/sf#436 but the sf library explicitly provides support for base R plotting, whereas you folks explicitly provide support in leaflet. The package creator @edzer was responsible for fixing issue 436, I'll link these two issues together. |
The error message seems to come from |
… overlay There seems to be an issue when the sf package is plotting on a leaflet map a spatial dataframe where there are no points. Every time I performed a subset of the LAPD data where there were no points in the subsetted region, I would get the message: "Error: is.matrix(x) || inherits(x, "XY") is not TRUE." After research, it seems to be related to this rstudio/leaflet#452 which is still not resolved as of 8/29. To get around this, I created an observe() event paired with an if/else to check whether the length of the subset was > 0. If so, it will add Markers to the plot, and if not, won't do anything. I set the observeEvent to changes in the input geography name.
Fix #452: Leaflet returns an error for empty "sf" "dataframe" objects
Thanks for the input, everyone. This should be all set, AFAICT. |
Leaflet handles empty tibbles happily:
However, an sf object containing zero observations (0 rows) returns an error without a leaflet object:
The text was updated successfully, but these errors were encountered: