我想知道如何根据输入的变化来改变Shiny和Leaflet来绘制点,而不重绘整个地图.
我正在使用的代码是:
library(leaflet)
library(shiny)
library(dplyr)
library(readr)
ui <- fluidPage(
titlePanel("Melbourne Urban Tree Visualisation"),
leafletOutput("treedat"),
uiOutput("precinct")
#Giving an input name and listing out types to choose in the Shiny app
)
server <- function(input, output){
#td <- read.csv("treedata.csv", header = TRUE)
#pal <- colorNumeric(
#palette = "RdYlGn",
#domain = td$LifeExpectencyValue
#)
output$precinct <- renderUI({
choices <- as.character(unique(td$Precinct))
choices <- c('All', choices)
selectInput(inputId = "precinct", label = "Precinct", choices = choices, selected = "CBD")
})
output$treedat <- renderLeaflet({
#if(is.null(td)) return()
## get …Run Code Online (Sandbox Code Playgroud) 我想在传单地图上显示加拿大的多边形.
# create map
library(leaflet)
m = leaflet() %>% addTiles()
m
Run Code Online (Sandbox Code Playgroud)
我能够找到加拿大的多边形:http://www.gadm.org/country.我为R选择了SpatialPolygonsDataFrame格式,但还有其他格式可用(例如Shapefile)
# load object in R
load("country_polygons/CAN_adm0.RData")
pol_can <- gadm
Run Code Online (Sandbox Code Playgroud)
如何在地图上显示形状?我假设我必须利用sp包,但我无法弄清楚如何这样做.非常感谢您的帮助!