【发布时间】:2016-09-11 22:50:11
【问题描述】:
我正在尝试在 R 中创建一个交互式网络地图,以使用 Shiny 和 Leaflet 显示位置
这个想法是用户选择一个输入并且与该输入相对应的标记(将从相应输入的数据集中获取的纬度/经度)显示在传单地图中(具有放大/缩小功能) . 任何帮助/建议将不胜感激!
(此处上传的样本数据文件):
enter code here
Server.R
library(shiny)
library(rpart.plot)
library(leaflet)
shinyServer(
function(input, output) {
output$dtmplot <- renderPlot({
dtmplot <- rpart.plot(dtm, type=4, extra=101)
})
observe({
output$map <- renderLeaflet( {
for(j in 1:nrow(df))
{
if(df[j, "col1"]==input$input1) {
map <- leaflet() %>%
addTiles() %>%
addMarkers(lng=df[j,"Longitude"], lat=df[j,"Latitude)
}
}
})
})
}
)
enter code here
UI.R
library(shiny)
library(leaflet)
shinyUI(
pageWithSidebar(
headerPanel("Sample project"),
sidebarPanel(
plotOutput("dtmplot"),
selectInput("input1",
label = "label1:",
choices = c(“choice1”,”choice2”),
selected = " choice1"),
sliderInput("slider","Please select slider input", min=1,max=100,value=20,step=10)
),
mainPanel(
leafletOutput("map")
)
))
【问题讨论】:
-
考虑在here 可用的代码行上重做您的示例,以便将其粘贴并作为一个
*.R文件执行。