我正在使用r spark中的复选框来选择不同数据集(例如,游乐场,图书馆,公园)绘制的位置。由于纬度和经度存在于不同的数据集中,我认为我可以使用for循环来更新基本的传单地图,具体取决于选中的复选框。但是,由于没有出现地图,因此我并没有取得太大的成功。我也没有错误。我也附上了代码片段。如果有人可以帮助我,这将非常有帮助。如果有人可以建议另一种方法来完成任务,我将不胜感激。
################### ui tabPanel("Other out-of-school resources",
fluidPage(sidebarLayout(
sidebarPanel(
selectInput("neighborhoods_other", "Select the neighborhood from the dataset", choices = c("No neighborhood selected", neighborhoods_other)),
br(),
checkboxGroupInput("program_other", "Select the type of the program", choices = c("Parks", "Playgrounds", "Rec Centers", "Libraries",
"Museums", "Fields"), selected = "Parks"),
br(),
radioButtons("demographics_other", "Select the demographics variable", choices = c("Median household income ($)","High school degree or equivalent(%)",
"Hispanic population (%)", "Non native English speakers (%)"), selected = character(0)),
br()
),
mainPanel(
tabsetPanel(type = "tab",
tabPanel("Map",
leafletOutput("mymap_other", height = 650)),
tabPanel("Data",
DT::dataTableOutput("datatable_other")),
tabPanel("Summary analysis")
)
))
)
)
###########服务器
colm_other = reactive({
input$program_other
})
parks_data = reactive({
if(input$neighborhoods_other != "No neighborhood selected" ) {
a = parks[which(parks[, "nbhd_name"] == input$neighborhoods_other),]
}
else {
a = parks
}
return(a)
})
libraries_data = reactive({
if(input$neighborhoods_other != "No neighborhood selected" ) {
a = libraries[which(libraries[, "nbhd_name"] == input$neighborhoods_other),]
}
else {
a = libraries
}
return(a)
})
output$mymap_other = renderLeaflet({
parks_data1 = parks_data()
libraries_data1 = libraries_data()
m = leaflet() %>% setView(lng = -104.991531, lat = 39.742043,zoom = 10) %>% addTiles()
for (col in colm_other()){
if(col == "Parks"){
print(head(parks_data1))
map <- m %>% addMarkers(map = m, lng = jitter(parks_data1$long), lat = jitter(parks_data1$lat))
}
if(col == "Libraries"){
print(col)
map %>% addMarkers(map, lng = jitter(libraries_data1$long), lat = jitter(libraries_data1$lat))
}
}