R 为什么在函数中调用传单时不显示地图
我想使用传单自定义一些绘图函数。我的问题是,在函数中使用传单时,地图不会立即显示在html中。有人知道解决办法吗 下面是一个例子,也是我尝试过的:R 为什么在函数中调用传单时不显示地图,r,leaflet,R,Leaflet,我想使用传单自定义一些绘图函数。我的问题是,在函数中使用传单时,地图不会立即显示在html中。有人知道解决办法吗 下面是一个例子,也是我尝试过的: Save this as .Rmd ```{r, c1, echo = FALSE} map <- function() { library(leaflet) m <- leaflet(width = "100%") %>% addTiles(group = "OSM") %>% addProvider
Save this as .Rmd
```{r, c1, echo = FALSE}
map <- function() {
library(leaflet)
m <- leaflet(width = "100%") %>%
addTiles(group = "OSM") %>%
addProviderTiles("Stamen.TonerLite") %>%
addLayersControl(
baseGroups = c("OSM", "Stamen.TonerLite"))
return(m)
}
map_poa <- function() {
m <- map()
m %>% addCircleMarkers(lat = c(47, 47.5),
lng = c(8, 8.5),
stroke = FALSE,
radius = 10,
fillOpacity = 0.8,
clusterOptions = markerClusterOptions())
print(m)
return(m)
}
```
如果没有函数,所有内容都会显示:
Add this chunk to the above .Rmd
```{r, c3, echo = FALSE}
m <- map()
m %>% addCircleMarkers(lat = c(47, 47.5),
lng = c(8, 8.5),
stroke = FALSE,
radius = 10,
fillOpacity = 0.8,
clusterOptions = markerClusterOptions())
print(m)
```
将此块添加到上面的.Rmd
```{r,c3,echo=FALSE}
m%添加循环标记(lat=c(47,47.5),
液化天然气=c(8,8.5),
笔划=假,
半径=10,
填充不透明度=0.8,
clusterOptions=markerClusterOptions())
打印(m)
```
您需要在map\u poa()
map\u poa您需要在map\u poa()中将addCircleMarkers
调用分配给mapm
map\u poa在函数中使用return时需要分配(%
)。请参阅下面我的答案。在函数中使用return时,需要分配(%
)。见下面我的答案。
Add this chunk to the above .Rmd
```{r, c3, echo = FALSE}
m <- map()
m %>% addCircleMarkers(lat = c(47, 47.5),
lng = c(8, 8.5),
stroke = FALSE,
radius = 10,
fillOpacity = 0.8,
clusterOptions = markerClusterOptions())
print(m)
```
map_poa <- function() {
m <- map()
# m <- m %>% addCircleMarkers( # also ok
m <- addCircleMarkers(map = m,
lat = c(47, 47.5),
lng = c(8, 8.5),
stroke = FALSE,
radius = 10,
fillOpacity = 0.8,
clusterOptions = markerClusterOptions())
return(m)
}