Geomapping Data in Shiny

柔情痞子 提交于 2019-12-24 10:37:18

问题


I have two set of data that I am attempting turn into geomaps using rshiny. I have been able to get the coordinates of my locations, and have been able to get them mapped on R. I am now starting my coding block for Shiny.

Sample Data:

  | X1 | Location          | Longitude | Latitude    |
1 | 1  | Brooklyn, NY, USA | 40.678178 | -73.9441579 |
2 | 2  | Liverpool, UK     | 53.408371 | -2.9915726  |

My ui returns my titles and select boxes, but regardless of what I put in my server I am not getting anything else on my map. Does anyone know what line of code I should run to get a CSV of my coordinates onto my shiny app? Or if I should just make my output into images of my maps instead?

Here is the code I've been working with so far:

library (shiny)
library (leaflet)
ui <- fluidPage(
 titlePanel("Sentiments of #Breastfeeding Reactions") ,
  selectInput("var",
              label = "Choose a sentiment to display",
              choices = list("Positive", "Negative"), 
              selected = "Positive")
  leafletOutput("PositiveMap")
server <- function(input, output)
shinyApp(ui = ui, server = server)

The data frames I am trying to work with are "A.CSV" for positive sentiment and "B.CSV" for negative sentiment. I've watched the shiny tutorial, but remain unsure of how to plot my data. `


回答1:


For specific help, you'll need to share your server code. However, here's the basic jist of how it should (could) look:

output$PositiveMap <- renderLeaflet({
leaflet() %>% setView(lat=37.68,lng=-97.33,zoom=4) %>% 
addTiles() %>% addMarkers(lng = A$Longitude, lat =A$Latitude )
)}


来源:https://stackoverflow.com/questions/43860417/geomapping-data-in-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!