• <bdo id='LcUKP'></bdo><ul id='LcUKP'></ul>
    <i id='LcUKP'><tr id='LcUKP'><dt id='LcUKP'><q id='LcUKP'><span id='LcUKP'><b id='LcUKP'><form id='LcUKP'><ins id='LcUKP'></ins><ul id='LcUKP'></ul><sub id='LcUKP'></sub></form><legend id='LcUKP'></legend><bdo id='LcUKP'><pre id='LcUKP'><center id='LcUKP'></center></pre></bdo></b><th id='LcUKP'></th></span></q></dt></tr></i><div id='LcUKP'><tfoot id='LcUKP'></tfoot><dl id='LcUKP'><fieldset id='LcUKP'></fieldset></dl></div>
  • <legend id='LcUKP'><style id='LcUKP'><dir id='LcUKP'><q id='LcUKP'></q></dir></style></legend>
    <tfoot id='LcUKP'></tfoot>

  • <small id='LcUKP'></small><noframes id='LcUKP'>

      1. 在 R 中自定义传单弹出窗口

        时间:2023-08-08
        • <small id='fUdhI'></small><noframes id='fUdhI'>

            <tbody id='fUdhI'></tbody>

              <legend id='fUdhI'><style id='fUdhI'><dir id='fUdhI'><q id='fUdhI'></q></dir></style></legend>

                <i id='fUdhI'><tr id='fUdhI'><dt id='fUdhI'><q id='fUdhI'><span id='fUdhI'><b id='fUdhI'><form id='fUdhI'><ins id='fUdhI'></ins><ul id='fUdhI'></ul><sub id='fUdhI'></sub></form><legend id='fUdhI'></legend><bdo id='fUdhI'><pre id='fUdhI'><center id='fUdhI'></center></pre></bdo></b><th id='fUdhI'></th></span></q></dt></tr></i><div id='fUdhI'><tfoot id='fUdhI'></tfoot><dl id='fUdhI'><fieldset id='fUdhI'></fieldset></dl></div>
                  <bdo id='fUdhI'></bdo><ul id='fUdhI'></ul>
                  <tfoot id='fUdhI'></tfoot>
                  本文介绍了在 R 中自定义传单弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 RStudio 创建一个等值线传单地图.我在导入到 R 的 shapefile 中有 Country 和 Url 作为属性.

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

                  以下是我目前使用的代码:

                  m <- world_shapefiles %>%传单() %>%addProviderTiles(providers$Esri.WorldStreetMap) %>%添加多边形(标签=〜国家,labelOptions = labelOptions(style = list("font-weight" = "normal", padding = "3px 8px", textsize = "15px",方向=自动")),popup = ~ paste("国家:", 国家, "<br/>","<b/>","URL:", url))

                  我想在弹出窗口中看到文本单击此处"而不是整个 url,我尝试使用以下代码但没有成功.

                  popup = ~ paste("Country:", counry, "<br/>","<b/>","URL:", "<b><a href=url>点击这里</a></b>")

                  有什么想法可以实现吗?

                  解决方案

                  概览

                  看完

                  # 加载必要的包图书馆(传单)图书馆(SF)# 下载压缩文件下载文件(url = "http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip", destfile = "TM_WORLD_BORDERS-0.3.zip")# 解压解压缩(zipfile =TM_WORLD_BORDERS-0.3.zip")# 转换为 sf世界.边界 <-read_sf(dsn = getwd(),层=TM_WORLD_BORDERS-0.3")# 添加每个国家的维基百科页面world.borders$wiki <-paste0("https://en.wikipedia.org/wiki/", world.borders$NAME)# 制作传单地图我的.map <-传单(选项=传单选项(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(数据 = world.borders, 填充 = "#D24618", 颜色 = "#D24618", 不透明度 = 0.5, 填充不透明度 = 0.01, 重量 = 3, 弹出 = paste0(<b>国家:</b>", world.borders$NAME, "<br>", "

                  I am using RStudio to create a choropleth leaflet map. I have Country and Url as an attribute in the shapefile that I imported to R.

                  I wish to show the Country name and URL as a hyperlink within the popup of the final map.

                  Below is the code I have used so far:

                  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)
                  )
                  

                  I want to see the text "Click here" instead of the entire url in the popup, I tried using the below code with no luck.

                  popup = ~ paste("Country:", counry, "<br/>","<b/>","URL:", "<b><a href=url>Click Here</a></b>")
                  

                  Any ideas to achieve it?

                  解决方案

                  Overview

                  After reading R, leaflet package, Passing a character vector of HTML tags to popups?, here's how you would modify your existing code:

                  # 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>"
                                 )
                  

                  Reproducible Example

                  I use the World Borders Data Set to download shapefiles for each country in the world. I then add a Wikipedia URL for each country in the data set.

                  # 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 #
                  

                  这篇关于在 R 中自定义传单弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  • <bdo id='dTNs7'></bdo><ul id='dTNs7'></ul>
                    <i id='dTNs7'><tr id='dTNs7'><dt id='dTNs7'><q id='dTNs7'><span id='dTNs7'><b id='dTNs7'><form id='dTNs7'><ins id='dTNs7'></ins><ul id='dTNs7'></ul><sub id='dTNs7'></sub></form><legend id='dTNs7'></legend><bdo id='dTNs7'><pre id='dTNs7'><center id='dTNs7'></center></pre></bdo></b><th id='dTNs7'></th></span></q></dt></tr></i><div id='dTNs7'><tfoot id='dTNs7'></tfoot><dl id='dTNs7'><fieldset id='dTNs7'></fieldset></dl></div>
                    <legend id='dTNs7'><style id='dTNs7'><dir id='dTNs7'><q id='dTNs7'></q></dir></style></legend>
                  • <tfoot id='dTNs7'></tfoot>
                      <tbody id='dTNs7'></tbody>

                          <small id='dTNs7'></small><noframes id='dTNs7'>