Hello,
I'm having a problem with the 'reactive' and 'observe' parts of the shiny Server code. The code below will produce a leaflet map but wont show the polygons due to the error. I need some advice on how to construct both reactive and observe code.
Code:-
library(sf)
library(shiny)
library(leaflet)
library(rgdal)
library(spData)
hedra <- rgdal::readOGR("data.geojson")
names(hedra)
hedra <- spTransform(hedra,CRS("+init=epsg:4326"))
plot(hedra,axes=TRUE)
ui <- fluidPage(
titlePanel("House buying completions between 2015 - 2019"),
sidebarLayout(
sidebarPanel(
helpText("You can create interactive demographic maps for housing completions between the years 2015 and 2019"),
selectInput(inputId = "var",
label = "Choose a completion year to display",
choices = c("Completions 2019", "Completions 2018",
"Completions 2017", "Completions 2016", "Completions 2015",
"Completions Total"),
selected = "Completions Total"),
sliderInput(inputId = "range",
label = "No. of properties:",
min = 0, max = 106, value = c(0, 106))
),
mainPanel(leafletOutput(outputId = "map"))
)
)
server <- function(input, output) {
output$map <- renderLeaflet({
leaflet() %>% addProviderTiles("OpenStreetMap.HOT", group = "OpenStreetMap.HOT") %>%
setView(-3.4710, 51.8633, zoom = 9) %>%
addPolygons(data = hedra[hedra$var < input$var, hedra$range < input$range])})
}
# ShinyApp Function:
shinyApp(ui, server)
Error:
Listening on http://###.##.#.##:####
Warning in polygonData.SpatialPolygonsDataFrame(data) :
Empty SpatialPolygonsDataFrame object passed and will be skipped