R,传单包,将 HTML 标签的字符向量传递给弹出窗口?

问题描述 投票:0回答:1

我正在尝试模拟 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)
      )
html r shiny r-leaflet
1个回答
3
投票

我认为您使用了错误的引号字符串。

而不是
'
。如果我像这样反转引号字符串,它对我有用:

'<a href="https://www.allaboutbirds.org/guide/Gadwall/id">more info</a>'

双引号来转义 URL。

© www.soinside.com 2019 - 2024. All rights reserved.