2016-06-16 40 views
0

我試圖模仿https://rstudio.github.io/leaflet/popups.html上的第一個例子,但使用了html標籤而不是一個向量。R,傳單包,將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) 
    ) 
+0

也可以看看[這個答案](http://stackoverflow.com/questions/29173336/how-to-display-advanced-customed-popups-for-leaflet-in-shiny)更精緻的彈出窗口。 –

回答

2

我想你使用的是錯誤的引號字符串。 而不是'。它適用於我,如果我反轉引號字符串,如下所示:

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

雙引號來轉義URL。

相關問題