【发布时间】:2015-09-02 16:19:27
【问题描述】:
我正在制作一个 R Shiny 应用程序,用户将在其中输入他们的城市、州和邮政编码,按下一个按钮,然后他们的位置(经纬度)将成为地图的新中心。输入是通过服务器中的这部分代码收集的。R:
output$ntextCounter <- eventReactive(input$goButton, {
citySelected <- as.character(input$city)
stateSelected <- as.character(input$state)
zipCodeSelected <- as.character(input$zipCode)
location2 <- stri_detect(paste(as.character(input$city),
as.character(input$state), as.character(input$zipCode), sep=", "), fixed = locationData$Location, opts_regex=stri_opts_regex(case_insensitive=TRUE))
counter <<- counter + 1
lat1 <- as.numeric(locationData[which(location2),]$latitude)
lon1 <- as.numeric(locationData[which(location2),]$longitude)
return(c(lat1, lon1))
})
我可以使用以下方法在 UI 中轻松查看新的纬度/经度值:
verbatimTextOutput("ntextCounter")
但我需要能够将这些值“return(c(lat1, lon1))”传递到 ui.r 的传单地图中的 center = c(Lat, Lon):
leafletMap("map", "100%", 365,
initialTileLayer = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
initialTileLayerAttribution = HTML('© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'),
options=list(center = c(38.25, -93.85), zoom = 4, maxBounds = list(list(1, -180), list(78, 180))
)),
我在 c(38.25, -93.85) 有一个初始地图中心,但最终我希望能够从 ntextCounter 传递它的变化值。我不确定这是范围界定问题还是什么,但我需要帮助将新的纬度/经度值放入传单地图中心。
任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: r maps parameter-passing shiny leaflet