本文介绍了将超链接添加到Shiny中的Leaflet弹出窗口的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用shiny中的leaflet制作交互式地图.从CSV提取弹出式窗口的数据:

Using leaflet in shiny to make an interactive map. Pulling data for popups from a CSV:

Row on CSV:
Name    lat          lng
Tufts   42.349598   -71.063541

R上标记的代码:

m %>% addMarkers(~lng, ~lat, icon = custommarker1 popup = ~htmlEscape(Name))

这会在正确的位置返回标记,并弹出显示"tufts"

This returns marker in correct spot with popup displaying 'tufts'

想知道是否有一种方法可以直接在CSV中将超链接编码到弹出窗口中?或者可以将纯文本作为新的CSV列放入并具有R/Shiny,然后将其转换为超链接.

Wondering if there is a way to encode a hyperlink into the popup directly in the CSV?Oor to put plain text as a new CSV column and have R/Shiny then turn it into a hyperlink.

shiny/leaflet的新手,将为您提供帮助!

Very new to shiny/leaflet and would appreciate any help!

推荐答案

只需在弹出窗口中将链接添加为html:

Just include the link in the popup as html:

output$mymap <- renderLeaflet({
m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=174.768, lat=-36.852, popup= '<a href = "https://rstudio.github.io/leaflet/"> R </a>')
m  # Print the map
})

您也可以将弹出窗口设置为等于数据框中的一列.如果您的数据框名为df,并且包含经度=长,纬度=纬度和网址=链接:

You can set the popup equal to a column in your dataframe as well. If your dataframe was called df and it contained longitude = long, latitude= lat, and urls = link :

output$mymap <- renderLeaflet({
m <- leaflet() %>%
addTiles() %>%  # Add default OpenStreetMap map tiles
addMarkers(lng=df$long, lat=df$lat, popup= df$link)
m  # Print the map

})

这篇关于将超链接添加到Shiny中的Leaflet弹出窗口的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:54