私は、ボストンの近隣ポリゴンとの渋滞停止の視覚化を行っています。ここではスケールダウン動作するコードです:私が何をしたいかleafletproxyの複数のポリゴンのループ?
library(shiny)
library(leaflet)
library(plyr)
library(dplyr)
library(rgdal)
#setwd
setwd("C:/Users/580048/Downloads")
#read hubway station data
hubway <- read.csv("Hubway_Stations.csv")
#read shapefiles
neighborhoods <-readOGR("C:/Users/580048/Downloads/bosneigh/Bos_neighborhoods_new.shp","Bos_neighborhoods_new")
neighborhoods <- spTransform(neighborhoods, CRS("+proj=longlat +datum=WGS84"))
#ui layout
ui <- bootstrapPage(
#style of tags
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
tags$style(type = "text/css", 'label[for="range"] {color: white;}'),
tags$style(type = "text/css", 'label[for="range2"] {color: white;}'),
tags$style(type = "text/css", 'label[for="team"] {color: white;}'),
tags$style(type = "text/css", 'label[for="away"] {color: white;}'),
tags$style(type = "text/css", 'label {color: white;}'),
#the map
leafletOutput("bosmap", width = "100%", height = "100%")
)
#server functions
server <- function(input, output, session) {
#plot static map
output$bosmap <- renderLeaflet({
leaflet(randomtaxi) %>%
addProviderTiles("CartoDB.DarkMatterNoLabels",
options= providerTileOptions(opacity = 0.99)) %>%
fitBounds(-71.0, 42.3, -71.1, 42.4)
})
#plot filtered cabs
observe({
longMark <- -71.0589
latMark <- 42.3601
poppy <- "Boston"
hotBorough <- subset(neighborhoods, neighborhoods$Name %in% c("Allston"))
totalBorough <- subset(neighborhoods, neighborhoods$Name %in% c("Back Bay"))
leafletProxy("bosmap", data = hubway) %>%
clearShapes() %>% clearMarkers %>% clearPopups() %>%
addPolygons(data = subset(neighborhoods, neighborhoods$Name %in% c(toString(neighborhoods$Name[1]))),
stroke = FALSE,
color = "red",
smoothFactor = 0.5,
fillOpacity = 0.3,
popup = toString(neighborhoods$Name[1])) %>%
addPopups(longMark, latMark, poppy,
options = popupOptions(closeButton = FALSE)
) %>%
addCircles(~hubway$long_,
~hubway$lat,
radius = 200,
weight = 20,
stroke = FALSE, fillOpacity = 0.5)
})
}
shinyApp(ui, server)
はをループし)(leaftletproxy内のforループを作成し、ボストンの26地区の各のための個々のポリゴンを作成している - このような何か:
leafletProxy("bosmap", data = hubway) %>%
clearShapes() %>% clearMarkers %>% clearPopups() %>%
for(i in 1:26){
addPolygons(data = subset(neighborhoods, neighborhoods$Name %in% c(toString(neighborhoods$Name[i]))),
stroke = FALSE,
color = "red",
smoothFactor = 0.5,
fillOpacity = 0.3,
popup = toString(neighborhoods$Name[i])) %>%
}
addPopups(longMark, latMark, poppy,
options = popupOptions(closeButton = FALSE)
) %>% ...(and so on)
しかし、何らかの理由で、leafletProxy()内にループを置くのが好きではないようです - 別のポップアップ、色、値を付けることができるいくつかの異なるポリゴンをプロットする簡単な方法はありますか? ?ここ
ボス周辺ファイル:https://data.cityofboston.gov/City-Services/Boston-Neighborhood-Shapefiles/af56-j7tb
hubway局:私はそれ%>% for(){}
がfor
と%>%
を使用する適切な方法ではありません@warmoverflowに同意http://bostonopendata.boston.opendata.arcgis.com/datasets/ee7474e2a0aa45cbbdfe0b747a5eb032_4
私はそれがループ内のforループをサポートしていない '%>% '演算子だと思いますか?そうであれば、途中でチェーンを壊して、forループを使用し、必要に応じてチェーンを再度使用することができます。 –