我正在尝试模拟 https://rstudio.github.io/leaflet/popups.html 上的第一个示例,但使用的是 html 标签向量而不是一个。
示例https://rstudio.github.io/leaflet/popups.html:
内容
[1] "<b><a href='http://www.samurainoodle.com'>Samurai Noodle</a></b><br/>606 5th Ave. S<br/>Seattle, WA 98138"
我的:
鸟$html[1]
[1] "<a href=‘https://www.allaboutbirds.org/guide/Gadwall/id’>more info</a>"
但是,当我将代码传递给传单弹出窗口时,更多信息超链接会显示并链接到未找到的页面而不是网址。我是否必须向 HTML 标记添加任何特殊字符(例如斜杠或引号)?有什么想法吗?
leaflet () %>%
addTiles(urlTemplate = base_map, attribution = mb_attribution)%>%
addMarkers(bird$lon, bird$lat,
popup=paste(sep="","<b>", bird$Common.Name,"</b>",
"<br/>","<font size=2 color=#045FB4>","Scientific Name: ","</font>" ,bird$Scientific.Name,
"<br/>","<font size=2 color=#045FB4>","Number Observed: ","</font>", bird$Count,
"<br/>","<font size=2 color=#045FB4>","Location: ","</font>", bird$Location,
"<br/>","<font size=2 color=#045FB4>","Region: ","</font>", bird$Area,
"<br/>","<font size=2 color=#045FB4>", "Date: ", "</font>", bird$Date,
"<br/>", bird$html),
clusterOptions = markerClusterOptions()) %>%
addPopups(bird$lon, bird$lat, bird$html, options = popupOptions(closeButton = FALSE)
)
我认为您使用了错误的引号字符串。
’
而不是'
。如果我像这样反转引号字符串,它对我有用:
'<a href="https://www.allaboutbirds.org/guide/Gadwall/id">more info</a>'
双引号来转义 URL。