所以我正在 R Studio 中使用传单,并尝试将一些 HTML 代码包含到图标的弹出窗口和标签中。 我只是不明白为什么它适用于弹出窗口而不适用于标签。
这是我的代码:
library(leaflet)
library(htmlwidgets)
library(htmltools)
leaflet(MerchCoOrds) %>% addTiles() %>%
addCircleMarkers(data=MerchCoOrds, lng=~MerchLongitude, lat=~MerchLatitude, col = ~pal(MerchCoOrds$merchant_state),
stroke = FALSE, fillOpacity = 1.0,
popup=~paste("<h3 >Merchant ID:</h3>",MerchCoOrds$merchant_id, "<h3 >Transaction ID:</h3>",
MerchCoOrds$transaction_id, sep=" "),
label=paste(htmltools::HTML("<h3 >Merchant State:</h3>"), MerchCoOrds$merchant_state,
htmltools::HTML("<h3 >Merchant Suburb:</h3>"), MerchCoOrds$merchant_suburb, sep=" ")) %>%
addLegend(pal=pal,values =~MerchCoOrds$merchant_state, opacity=1, title="State of Transaction",
position="bottomright") %>%
addControl(title, position="topright")
我已经尝试过以
htmltools::HTML
开始该行,并以与弹出窗口相同的方式进行操作(仅使用粘贴功能),但对于标签都不起作用。
当我运行代码并将鼠标悬停在图标上时,它会在正确粘贴商人州名称之前显示 我想知道标签是否出于某种原因不支持 HTML。
另外,作为一个快速注释,我在所有代码中放置了一个空格,这样它就不会在本文中自动转换为 HTML。
好的对不起大家。
我在第3.5节找到了解决方案: https://rstudio-pubs-static.s3.amazonaws.com/307862_b8c8460272dc4a2a9023d033d5f3ec34.html
我将保留该帖子,以防其他人遇到此问题。
这是按我的预期工作的最终代码 在此输入图片描述