Html 在R中自定义单张弹出窗口

Html 在R中自定义单张弹出窗口,html,r,leaflet,gis,arcgis-js-api,Html,R,Leaflet,Gis,Arcgis Js Api,我正在使用RStudio创建choropleth传单地图。 我在导入到R的shapefile中有Country和Url作为属性 我希望在最终地图的弹出窗口中以超链接的形式显示国家名称和URL 以下是我迄今为止使用的代码: m <- world_shapefiles %>% leaflet() %>% addProviderTiles(providers$Esri.WorldStreetMap) %>% addPolygons( lab

我正在使用RStudio创建choropleth传单地图。 我在导入到R的shapefile中有Country和Url作为属性

我希望在最终地图的弹出窗口中以超链接的形式显示国家名称和URL

以下是我迄今为止使用的代码:

m <- world_shapefiles %>%
  leaflet() %>%
  addProviderTiles(providers$Esri.WorldStreetMap) %>%      
  addPolygons( 
      label=~country, 
            labelOptions = labelOptions(style = list("font-weight" = "normal", padding = "3px 8px", textsize = "15px",
direction = "auto")), 
              popup = ~ paste("Country:", country, "<br/>","<b/>","URL:", url)
)
m%
传单()%>%
addProviderTiles(提供者$Esri.WorldStreetMap)%>%
添加多边形(
标签=~国家,
labelOptions=labelOptions(style=list(“font-weight”=“normal”、padding=“3px 8px”、textsize=“15px”,
direction=“auto”)),
弹出窗口=~粘贴(“国家:”,国家,
“,”,“URL:”,URL) )
我想看到文本“点击这里”,而不是在弹出的整个网址,我试图使用下面的代码没有运气

popup = ~ paste("Country:", counry, "<br/>","<b/>","URL:", "<b><a href=url>Click Here</a></b>")
popup=~粘贴(“国家:”,国家,“
”,“URL:”,“”)
有什么想法可以实现吗?

概述 阅读后,以下是如何修改现有代码:

# it seems ~ doesn't work inside of the paste0() function
# which is why I accessed the variables through the $
popup = paste0( "Country:"
                 , world_shapefiles$country 
                 , "<br>"
                 , "<a href='"
                 , world_shapefiles$url
                 , "' target='_blank'>"
                 , "Click Here</a>"
               )
#似乎~在paste0()函数中不起作用
#这就是为什么我通过$
弹出=粘贴0(“国家:”
,世界形状文件$国家
,“
” , "" )
可复制示例 我使用下载世界上每个国家的形状文件。然后,我为数据集中的每个国家添加一个URL

#加载必要的包
图书馆(单张)
图书馆(sf)
#下载zip文件
下载文件(
url=”http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip"
,destfile=“TM\u WORLD\u BORDERS-0.3.zip”
)
#解压
解压(zipfile=“TM_WORLD_BORDERS-0.3.zip”)
#转换为sf
世界边界%
添加多边形(数据=world.borders)
,fill=“#D24618”
,color=“#D24618”
,不透明度=0.5
,fillOpacity=0.01
,重量=3
,popup=0(
“国家:”
,world.borders$NAME
,“
” , "" ) ,label=~NAME ,labelOptions=labelOptions( 样式=列表(“字体重量”=“正常” ,padding=“3px 8px” ,textsize=“15px” ,direction=“auto”)) ,highlightOptions=highlightOptions( color=“#10539A” ,重量=3 ,fillColor=NA )) #显示地图 我的地图 #脚本结束#
# load necessary packages
library( leaflet )
library( sf )

# download zip file
download.file(
  url = "http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip"
  , destfile = "TM_WORLD_BORDERS-0.3.zip"
)

# unzip 
unzip( zipfile = "TM_WORLD_BORDERS-0.3.zip" )

# transfrom to sf
world.borders <-
  read_sf( dsn = getwd()
           , layer = "TM_WORLD_BORDERS-0.3" )

# add the wikipedia page for each country
world.borders$wiki <-
  paste0( "https://en.wikipedia.org/wiki/", world.borders$NAME )

# make leaflet map
my.map <-
  leaflet( options = leafletOptions( minZoom = 2 ) ) %>%
  setMaxBounds( lng1 = -180
                , lat1 = -89.98155760646617
                , lng2 = 180
                , lat2 = 89.99346179538875 ) %>%
  addTiles( urlTemplate = "https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}" ) %>%
  addPolygons( data = world.borders
               , fill = "#D24618"
               , color = "#D24618"
               , opacity = 0.5
               , fillOpacity = 0.01
               , weight = 3
               , popup = paste0(
                 "<b>Country: </b>"
                 , world.borders$NAME
                 , "<br>"
                 , "<a href='"
                 , world.borders$wiki
                 , "' target='_blank'>"
                 , "Click Here to View Wiki</a>"
               )
               , label = ~NAME
               , labelOptions = labelOptions(
                 style = list("font-weight" = "normal"
                              , padding = "3px 8px"
                              , textsize = "15px"
                              , direction = "auto" ) )
               , highlightOptions = highlightOptions( 
                 color = "#10539A"
                 , weight = 3
                 , fillColor = NA
               ))

# display map
my.map

# end of script #