2016-07-30 151 views
1

我想做一个闪亮的应用程序和它的一部分,是一个地图,应该打印经纬度点到地图。我一直在努力去做,但我得到一个错误,告诉我它找不到我的对象d绘制点(纬度和经度)到ggmap

如果我只是把地图工程好,没有点,但它是一个步骤。

我server.R代码:

#Reactive Map 
    output$MapPr <- renderPlot({ 
    d <- switch(input$chDatabase, 
       "BPD 2013 Baltimore" = read.csv("./Data/BPD_13_Bal.csv", 
               header=TRUE, sep=",", dec="."), 
       "BPD 2014 Baltimore" = read.csv("./Data/BPD_14_Bal.csv", 
               header=TRUE, sep=",", dec=".") 
    ) 
    library(ggmap) 
    map <- get_map(location = 'Baltimore', zoom = 12) 
    ggmap(map) 
    ggmap(map) + 
     geom_point(aes(as.numeric(d$Longitude), as.numeric(d$Latitude)), data = d, alpha =.5, color = "darkred") 
    }, width = 800, height = 700) 

在ui.R我有:

################################ 
#2nd tabpanel for Reactive Map 
tabPanel("Reactive Map", 

    #SideBarLayout for sidebar Panel for the options of the map  
    sidebarLayout(

    #SideBar Panel with options to adjust the map 
    sidebarPanel(

     #Databases selection 
     selectInput("chDatabaseMap","Choose DataBase:", 
      choices = c("BPD 2013 Baltimore", "BPD 2014 Baltimore")) 
    ), 
    ###################################  
    #Main panel to put plots 
    mainPanel(
     plotOutput("MapPr") 
    ) 
) 
) 

顺便说一句,我已经看到了与负荷问题csv文件,或者至少我认为,但是我已经用同一个系统做的以前的图(直方图,饼图,箱形图等),它们工作。

我不知道该如何继续。

纬度和经度的列都是数字。

回答

0

是否将server.R更改为以下工作?

library(ggmap) 

d <- reactive({ 
    switch(input$chDatabase, 
      "BPD 2013 Baltimore" = read.csv("./Data/BPD_13_Bal.csv", 
              header=TRUE, sep=",", dec="."), 
      "BPD 2014 Baltimore" = read.csv("./Data/BPD_14_Bal.csv", 
              header=TRUE, sep=",", dec=".")) 
}) 



output$MapPr <- renderPlot({ 
    df <- d() 
    map <- get_map(location = 'Baltimore', zoom = 12) 
    ggmap(map) + 
     geom_point(aes(as.numeric(Longitude), 
         as.numeric(Latitude)), 
        data = df, alpha =.5, color = "darkred") 
}, width = 800, height = 700) 
+0

现在我得到另一个;警告:类型'closure'的$:object中的错误不是子集合 – neoSmith

+0

我的错误。你可以请现在检查吗?不应该在'aes'内使用'$' – Sumedh

+0

是啊!它现在有效:D感谢@Sumedh!我也意识到另一个错误到我的CSV文件。 – neoSmith