【问题标题】:R, leaflet package, Passing a character vector of HTML tags to popups?R,传单包,将HTML标签的字符向量传递给弹出窗口?
【发布时间】:2016-10-17 10:22:40
【问题描述】:

我正在尝试模拟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>"

但是,当我将代码传递给传单弹出窗口时,更多信息超链接会显示并链接到未找到的页面而不是 url。我是否必须在 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)
      )

【问题讨论】:

  • 也可以查看this answer 以获得更详细的弹出窗口。

标签: html r url shiny leaflet


【解决方案1】:

我认为您使用了错误的引号字符串。 而不是 '。如果我这样反转引号字符串,它对我有用:

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

双引号转义 URL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多