R, leaflet package, Passing a character vector of HTML tags to popups?

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

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.

Example on https://rstudio.github.io/leaflet/popups.html:

content

[1] "<b><a href='http://www.samurainoodle.com'>Samurai Noodle</a></b><br/>606 5th Ave. S<br/>Seattle, WA 98138"

Mine:

bird$html[1]

[1] "<a href=‘https://www.allaboutbirds.org/guide/Gadwall/id’>more info</a>"

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)       )

回答1:

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>'

Double quotes to escape the URL.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!