在 Shiny 中绘制地理地图数据

问题描述 投票:0回答:1

我有两组数据,正在尝试使用 rshiny 将它们转换为地理地图。我已经能够获取我的位置的坐标,并且能够将它们映射到 R 上。我现在开始为 Shiny 编码。

样本数据:

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

我的用户界面返回我的标题和选择框,但无论我在服务器中放入什么,我都不会在地图上得到任何其他内容。有谁知道我应该运行哪行代码才能将我的坐标的 CSV 数据传输到我闪亮的应用程序上?或者我是否应该将输出变成地图图像?

这是我迄今为止一直在使用的代码:

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)

我尝试使用的数据框是“A.CSV”(表示积极情绪)和“B.CSV”(表示消极情绪)。我已经看过闪亮的教程,但仍然不确定如何绘制我的数据。 `

r shiny maps r-leaflet
1个回答
1
投票

要获得特定帮助,您需要共享您的服务器代码。然而,这是它应该(可能)看起来如何的基本要点:

output$PositiveMap <- renderLeaflet({
leaflet() %>% setView(lat=37.68,lng=-97.33,zoom=4) %>% 
addTiles() %>% addMarkers(lng = A$Longitude, lat =A$Latitude )
)}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.