Skip to content
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

Support for plotting terra objects appears to be broken in the current leaflet release #865

Closed
JosephStewart opened this issue Jun 18, 2023 · 2 comments

Comments

@JosephStewart
Copy link

Support for plotting terra objects appears to be broken in the current leaflet release.

install.packages('leaflet')
library(terra); library(leaflet); library(raster)
r <- rast(xmin=-2.8, xmax=-2.79, ymin=54.04, ymax = 54.05, nrow=30, ncol=30, crs="epsg:4326", vals=1:900)
leaflet() |> addTiles() |> addRasterImage(r, colors = "Spectral", opacity = 0.8)
# Error in addRasterImage(addTiles(leaflet()), r, colors = "Spectral", opacity = 0.8) : 
# inherits(x, "RasterLayer") is not TRUE
leaflet() |> addTiles() |> addRasterImage(raster(r), colors = "Spectral", opacity = 0.8)
# works (but slow)

Robert Hijman's version of leaflet works for plotting terra objects. See #728.

remotes::install_github("https://github.com/rhijmans/leaflet")
library(terra); library(leaflet);
# SpatRaster
r <- rast(xmin=-2.8, xmax=-2.79, ymin=54.04, ymax = 54.05, nrow=30, ncol=30, crs="epsg:4326", vals=1:900)
leaflet() |> addTiles() |> addRasterImage(r, colors = "Spectral", opacity = 0.8)
# works!
@GuiAlDuS
Copy link

GuiAlDuS commented Aug 1, 2023

It seems the issue is with the Leaflet version on CRAN, the current Github version is able to load the SpatRaster layers well:
devtools::install_github('rstudio/leaflet')

@gadenbuie gadenbuie mentioned this issue Aug 14, 2023
24 tasks
@gadenbuie
Copy link
Member

The latest version of leaflet is now on CRAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants