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

Interactive maps in articles #989

Closed
mtennekes opened this issue Dec 16, 2024 · 14 comments
Closed

Interactive maps in articles #989

mtennekes opened this issue Dec 16, 2024 · 14 comments
Labels

Comments

@mtennekes
Copy link
Member

Interactive maps don't work yet... https://r-tmap.github.io/tmap/articles/32_versus_mapview.html

They do work in mapview: https://r-spatial.github.io/mapview/articles/mapview_01-basics.html

@tim-salabim I checked your rmd code, but couldn't find out what did the trick.
(Also check out the content, and let me know your thoughts)

@Nowosad Nowosad added the bug label Dec 16, 2024
@tim-salabim
Copy link

I wouldn't trust what you see in the mapview pages right now. They're probably ancient, as the daily runs have been failing for quite some time now. The only thing I could imagine right from the top of my head is that mapview's knit_print is simply using the leaflet part (so relying on Posit to make sure things work).

Regarding content, there's only one thing. I'd prefer if you used zcol instead of z here

@mtennekes
Copy link
Member Author

@olivroy do you have any idea how to fix this? Not only relevant for this vignette, but also for a tmap-basics vignette about switching modes.

FYI: this is the last mapview commit that passed the automatic tests: https://github.com/r-spatial/mapview/tree/4202de2257214bd3c22b68fa8790e9596736fe83

@olivroy
Copy link
Contributor

olivroy commented Dec 20, 2024

Sorry for being unresponsive.. It seems very strange... I did some housekeeping in mapview to revive GitHub pages deployment r-spatial/mapview#497. And it seems that the maps are correctly deployed on their site :/
https://r-spatial.github.io/mapview/ in the vignettes look fine.

Maybe tmap is doing too much with its knit_print() method somehow? Maybe we could try if using dev leafem for deployment helps.. I am sending a PR shortly.

@olivroy
Copy link
Contributor

olivroy commented Dec 20, 2024

Maybe there is some sort of token that is required ?

I remember this from leaflet a couple months ago rstudio/leaflet#913 (comment) rstudio/leaflet#912

Maybe this is related?

@olivroy
Copy link
Contributor

olivroy commented Dec 20, 2024

dev leafem didn't work.. It is probably an issue with tmap knit_print method.. leaflet doesn't provide a knit_print() method. And it seems that tmap is resorting to knitr.. Perhaps it should delegate to `htmlwidget instead? htmlwidgets provides htmlwidgets:::knit_print.htmlwidget.

Maybe that if active. tmap should set the class to "htmlwidget" to help with S3 dispatch..

A leaflet map has class = c("leaflet", "htmlwidget")

@mtennekes
Copy link
Member Author

Very strange indeed. Also strange that leaflet doesn't provide a knit_print() method, and still works (at least, I assume)

@tim-salabim
Copy link

Very strange indeed. Also strange that leaflet doesn't provide a knit_print() method, and still works (at least, I assume)

I guess that's because a leaflet map is an htmkwidget

@mtennekes
Copy link
Member Author

mtennekes commented Dec 28, 2024

I guess that's because a leaflet map is an htmkwidget

Yes that's true. So what happens if we remove knit_print.tmap? The tmap small multiples are returned as objects of class "shiny.tag.list" (when tmap_leaflet is used), and there is a htmltools::knit_print.shiny.tag.list. So that should also be covered.

@tim-salabim
Copy link

That would be great!

@mtennekes
Copy link
Member Author

Not successful yet. After removing the knit_print.tmap, no maps are included.

It boils down to this problem: tmap_leaflet returns a leaflet object, but it is not printed (also not in the console). In the console, I have to print it:

print(tmap_leaflet(tm_shape(World) + tm_polygons()))

to make it appear.

However, in an Rmd file, this chunk:

tmap_mode("view")
print(tmap_leaflet(tm_shape(World) + tm_polygons()))

doesn't produce a map.

This does work:

library(leaflet)
leaflet() |> addTiles()

@mtennekes
Copy link
Member Author

(in addition)

Does not work:

tmap_mode("view")
tmap_leaflet(tm_shape(World) + tm_polygons())

Works:

tmap_mode("view")
lf = tmap_leaflet(tm_shape(World) + tm_polygons())
lf

@mtennekes
Copy link
Member Author

Even printing lf doesn't work with pkgdown. I did that in the tmap-mapview vignette:

Source: https://github.com/r-tmap/tmap/blob/master/vignettes/32_versus_mapview.Rmd
Rendered: https://r-tmap.github.io/tmap/articles/32_versus_mapview.html

as an attempt to workaround this issue.

@olivroy @tim-salabim any other tricks up your sleeves?

@tim-salabim
Copy link

Not really, just noticed that the rmd headers between tmap and mapview are quite different...

@olivroy
Copy link
Contributor

olivroy commented Jan 7, 2025

Not really, just noticed that the rmd headers between tmap and mapview are quite different...

Okay, this was the issue. #1021 fixed that. pkgdown: as-is: TRUE was probably the problem. Also height / width / retina was incorrect for interactive maps...

I will see if I didn't create new issues with the PR..

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

No branches or pull requests

4 participants