Ken Ken - 4 months ago 23
HTML Question

Adjust size of leaflet map in rmarkdown html

I'd like to change the height and width of

leaflet
map outputs in html document. Is there a simple way to do this in R markdown without getting into whole CSS business?

```{r}
library(leaflet)
library(dplyr)

m <- leaflet() %>% setView(lng = -71.0589, lat = 42.3601, zoom = 12)
m %>% addTiles()
```


Ideally, I want the width of map to be the same width of code block as shown below.

enter image description here

Answer

you can set like a global figure size to the whole document... But I think your code chunks will rescale, the images not.

library(knitr)
opts_chunk$set(fig.width=12, fig.height=8)

Actually, I didn't checked it with leaflets. Hope this code is still working.