问题描述
我尝试使用rshiny将两组数据转换为地理地图.我已经能够获取我的位置的坐标,并且能够将它们映射到R.现在,我开始为Shiny编写代码.
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.
样本数据:
| X1 | Location | Longitude | Latitude |
1 | 1 | Brooklyn, NY, USA | 40.678178 | -73.9441579 |
2 | 2 | Liverpool, UK | 53.408371 | -2.9915726 |
我的ui返回我的标题和选择框,但是无论我在服务器中放什么,我在地图上都看不到其他内容.有人知道我应该运行哪一行代码才能将坐标CSV导入我的闪亮应用程序吗?或者,如果我只是将输出结果转换成地图图像?
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)
我要使用的数据框是"A.CSV"表示正面情绪,"B.CSV"表示负面情绪.我已经看过精彩的教程,但是仍然不确定如何绘制数据.`
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.`
推荐答案
要获取特定帮助,您需要共享服务器代码.但是,这是它的外观(可能)的基本原理:
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 )
)}
这篇关于在Shiny中进行数据映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!