简体   繁体   English

地图中缺少标记/点

[英]Missing markers/points in map

I'm still new to Rshiny and the Leaflet package so need some help to see where I'm going wrong.我还是 Rshiny 和 Leaflet 包的新手,所以需要一些帮助来了解我哪里出错了。 I have previously asked a very similar question following which I recevied a solution which I am using.我之前问过一个非常相似的问题,然后我收到了我正在使用的解决方案。 This is a variation of the same question.这是同一问题的变体。

I have a UK postcode for which I have latitude and longitude values, lets call this the origin postcode.我有一个英国邮政编码,我有纬度和经度值,我们称之为原始邮政编码。 I have a data frame which contains other postcodes and their corresponding latitude and longitude.我有一个数据框,其中包含其他邮政编码及其相应的纬度和经度。 I have a sliding bar input which is the radius from the origin postcode in miles, with this having a range up to 200 miles.我有一个滑动条输入,它是以英里为单位的原始邮政编码的半径,其范围可达 200 英里。 I can load the app, but I can't see the other postcode markers appear on the map.我可以加载应用程序,但我看不到地图上显示的其他邮政编码标记。 I also get the below我也得到以下

Discarded datum OSGB_1936 in CRS definition Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO") : Discarded datum OSGB_1936 in CRS definition Discarded datum OSGB_1936 in CRS definition Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO") : Discarded datum OSGB_1936 in CRS definition

I post my code below:我在下面发布我的代码:

library(shiny)
library(leaflet)
library(shinyjs)
library(rgeos)
library(tidyverse)

crime_df <-
data.frame(Postcode = 
"WN1 3LU",box =2,
Latitude = 
53.546367,
Longitude = 
-2.620909)

crime <-
  data.frame(Postcode = 
               c("BL7 9YH","BT36 7WE"),box =c(7,1),
             Latitude = 
               c(53.613982,53.613982),
             Longitude = 
               -2.406439,-2.406439)
coordinates(crime) = ~Longitude+Latitude
proj4string(crime) = CRS("+init=epsg:4326")
crime <- spTransform(x = crime, CRS = CRS("+init=epsg:27700"))


ui <- fluidPage(shinyjs::useShinyjs(),
fluidPage(
# Give the page a title
titlePanel("Crime Map"),
mainPanel(leafletOutput("map")),

fluidRow(column(
3,
sliderInput(
"miles",
"Miles from location",
min = 1,
max = 200,
value = 100,
width = '120px'
)))))


server <- function (input, output, session) {
  output$map <- renderLeaflet({
    inside_df <- inside_df()
    leaflet(crime_df) %>%
      addTiles() %>%
      setView(lng = -1.525,
              lat = 55,
              zoom = 5) %>%
      addMarkers(
        lng = inside_df$Longitude,
        lat = inside_df$Latitude,
        popup = inside_df$Postcode
      )
  })


circle <- reactive({
location <- crime_df  %>%dplyr::select(Latitude, Longitude)
coordinates(location) <- ~Longitude+Latitude
proj4string(location) = CRS("+init=epsg:4326")
location <- spTransform(location, CRS = CRS("+init=epsg:27700"))
circle <- gBuffer(location, width = input$miles * 1609.34)
circle
})

inside_df <- reactive({
circle = circle()
inside = crime[circle,]  # find points inside the circle
inside = spTransform(inside,  CRS("+init=epsg:4326"))
inside_df = as.data.frame(inside)
inside_df
})
}

shinyApp(ui = ui, server = server)

Your data frame has both postcodes in the same location and contains an error.您的数据框在同一位置具有两个邮政编码并且包含错​​误。 Changing it as below更改如下

crime <-
    data.frame(
        Postcode = c("BL7 9YH", "BT36 7WE"),
        box = c(7, 1),
        Latitude =  c(53.613982, 54.66653),
        Longitude = c(-2.406439,-5.981969)
    )

yields this.产生这个。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM