我正在制作一个R Shiny应用程序,用户将输入他们的城市、州和邮政编码,按下一个按钮,然后他们的位置(纬度、经度)将成为地图的新中心。这些输入是通过server.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中leaflet地图的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传递更改后的值。我不确定这是否是作用域问题,但我需要帮助将新的纬度/经度值放入leaflet地图中心。
非常感谢您的任何帮助。提前致谢。