R,传单包,将HTML标签的字符向量传递给弹出窗口? [英] R, leaflet package, Passing a character vector of HTML tags to popups?
问题描述
我正在尝试在 https://rstudio.github.io/上模拟第一个示例leaflet/popups.html ,但带有html标签而不是一个.
I'm trying to emulate the first example on https://rstudio.github.io/leaflet/popups.html but with a vector of html tags rather than one.
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"
我的:
bird $ html [1]
bird$html[1]
[1] "<a href=‘https://www.allaboutbirds.org/guide/Gadwall/id’>more info</a>"
但是,当我将代码传递给传单弹出窗口时,将显示更多信息超链接,并链接到未找到的页面而不是URL.我是否必须在HTML标签中添加任何特殊字符(例如,斜杠或引号)?有什么想法吗?
However, when I pass the code to leaflet popup, the more info hyperlink displays and links to a not found page rather than the url. Do i have to add any special characters to the HTML tag (e.g. slashes or quotations)? Any thoughts?
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)
)
推荐答案
我认为您使用了错误的引号字符串. ’
代替'
.如果我这样反引号,它对我有用:
I think you're using a wrong quotation string. ’
instead of '
. It works for me if I reverse the quote string as so:
'<a href="https://www.allaboutbirds.org/guide/Gadwall/id">more info</a>'
用双引号引起来的URL.
Double quotes to escape the URL.
这篇关于R,传单包,将HTML标签的字符向量传递给弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!