Closed GitHunter0 closed 1 year ago
Hi @GitHunter0 . Thanks for opening this issue. There could be some kind of conflict with data.table
, but I'm not sure why.
library(plotly)
library(magrittr)
library(sf)
library(geobr)
# note the object has multiple classes
map_cities <- geobr::read_municipality(code_muni="all", year=2010)
class(map_cities)
> [1] "sf" "data.table" "data.frame"
If if try plot_ly()
, we get the error you pointed out.
plot_ly() %>% add_sf(data = map_cities)
> Error in `[.data.frame`(x, i) : undefined columns selected
Now, when we remove the data.table
class, then plot_ly()
works.
map_cities <- as.data.frame(map_cities) %>% st_sf()
class(map_cities)
> [1] "sf" "data.frame"
plot_ly() %>% add_sf(data = map_cities)
This looks a bit strange, to be honest. It looks like a bug on plotly
, but I cannot really grasp why it happens.
Hey @rafapereirabr , it makes some sense I believe, AFAIK data.table
has compatibility issues with sf
.
Probably map_cities
should not have data.table
class as default, since other maps from geobr
like map_regions
(from the example above) do not have it.
But I'm glad you found a workaround, thank you.
Yes, I should proabably remove the data.table
class from the data. I'll keep this issue open and will add this to my task list. Thanks,
Fixed in dev version with 45b99a20 .
Hi folks, for some reason the cities map is not working with
plotly
(while others like regions map are working flawlessly). Any idea what is happening?While this works:
This returns
Error in `[.data.frame`(x, i) : undefined columns selected
:Thank you