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

cannot render side-by-side interactive tmaps in Distill blog #451

Open
jarrodscott opened this issue Apr 8, 2022 · 2 comments
Open

cannot render side-by-side interactive tmaps in Distill blog #451

jarrodscott opened this issue Apr 8, 2022 · 2 comments
Labels
feature request 🗻 a feature request or enhancement

Comments

@jarrodscott
Copy link

jarrodscott commented Apr 8, 2022

Hi there

I am using the tmap package within a Distill blog-site. Basically I am trying to render two interactive HTML maps side-by-side, like so.

working

But instead, it looks like this, no matter what I do.

not_working

I originally thought this was a problem with tmap but the images render fine if I run the code chunk in RStudio. It also renders fine in a default R Markdown HTML document. The first image above was from a default R Markdown HTML document. It is worth noting that if I set tmap_mode("plot") instead of tmap_mode("view") the plots do render side-by-side in the Distill blog, but of course they are no longer interactive. Any thought? Thanks!

Reproducible example.

library(tmap)
library(tmaptools)
data("World")
tmap_mode("view")

facets <-  c("life_exp", "inequality")
tmp_tmap <- tm_shape(World) + 
  tm_polygons(facets) + 
  tm_facets(ncol = 2, sync = TRUE, nrow = 1) 

tmap_leaflet(tmp_tmap, show = FALSE)  
# Or calling the the tmap object directly
tmp_tmap
@cderv
Copy link
Collaborator

cderv commented Apr 11, 2022

This happens because distill applies a layout for figures (https://rstudio.github.io/distill/figures.html) and tmap_leaflet() outputs will be put in two l-body divs which is the default layout

This happens with tmap_mode("view") because 2 leaflet maps are outputed whereas with tmap_plot() only one image is outputed where the two plots are merged in the tmap plot creating process. (there is only one png file inserted in the document).

So this is a limitation in distill due to the feature of layout for figures.

I'll leave this open as a feature request to see if we can offer an option to opt-out a layout for htmlwidget and support this (where width attributes is used to organize the grid layout).

@cderv cderv added the feature request 🗻 a feature request or enhancement label Apr 11, 2022
@jarrodscott
Copy link
Author

great, thank you very much for the explanation @cderv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request 🗻 a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants