[英]Blank popup in leaflet R
I am trying to map San Francisco's crimes in a map. 我正在尝试在地图上绘制旧金山的罪行。 The below code intends to map every crime (lat, lng) and when the marker is clicked, show the "category" column of the dataset. 以下代码旨在映射每种犯罪(经纬度),单击标记时,将显示数据集的“类别”列。 Right now the below code shows a blank text box when I click the marker. 现在,当我单击标记时,下面的代码显示一个空白文本框。 Can anybody help? 有人可以帮忙吗?
sf <- read.csv("https://raw.githubusercontent.com/uwescience/datasci_course_materials/master/assignment6/sanfrancisco_incidents_summer_2014.csv")
crime <- data.frame(lat = c(sf$Y),
lng = c(sf$X))
cat <- c(sf$Category)
library(leaflet)
crime %>%
leaflet() %>%
addTiles() %>%
addMarkers(popup = paste(sf$Category), clusterOptions = markerClusterOptions())
Try the following: 请尝试以下操作:
sf <- read.csv("https://raw.githubusercontent.com/uwescience/datasci_course_materials/master/assignment6/sanfrancisco_incidents_summer_2014.csv")
library(leaflet)
sf %>%
leaflet() %>%
addTiles() %>%
addMarkers(lat = ~Y, lng = ~X, popup = ~Category, clusterOptions = markerClusterOptions())
I'm not sure what your issue is, but using the formula syntax allows leaflet to build the list of pop-up labels on its own and does not require calling paste
explicitly or subsetting the original dataframe. 我不确定您的问题是什么,但是使用公式语法可以使Leaflet自行构建弹出标签列表,并且不需要显式调用paste
或子集原始数据帧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.