I'm having trouble with the impact of a time slider on the circle markers of my interactive shiny/leaflet map. I need circle markers of different color for Fuel_Type (wind & solar), and for radius based of the Nameplate_capacity. Each project also needs to appear on/after its construction start year.
However, when I use the slider the marker size seems to change randomly, meaning some markers are inaccurate for some years, and giving the impression that the site characteristics are changing, when they are not. I have also tried to use addmarkers with custom markers, and the icons seems to change randomly between the projects over the years too.
Here's a portion of my data:
Site_Name Nameplate_Capacity Fuel_Type Construction_Start_Year Latitude Longitude
Beryl Solar Farm 98.4 Solar 2004 -32.35767 149.46648
Wemen Solar Farm 97.5 Solar 2010 -34.81318 142.56044
Karadoc Solar Farm 96.9 Solar 2011 -34.40928 142.25632
Crookwell Wind Farm 96.04 Wind 2015 -34.54083 149.59645
Hallett Stage Brown Hill 94.5 Wind 2007 -33.34865 138.75166
Manildra Solar Farm 94 Solar 2014 -33.17261 148.71472
Bango Wind Farm 240 Wind 2006 -34.56655 148.8488
Sunraysia Solar Farm 228.8 Solar 2008 -34.80279 143.4911
Collector 226.8 Wind 2008 -34.85983 149.39882
Murra Warra Wind Farm 225.7 Wind 2009 -36.43133 142.32266
Limondale Solar Farm 220 Solar 2011 -34.77145 143.50868
Wellington Solar Farm 211.2 Solar 2012 -32.51744 148.95352
Port Augusta Renewable Energy Park 210 Wind 2018 -32.55722 137.84978
and here's the code I used:
library(leaflet)
library(shiny)
#read in data
leafletdf <- read_csv("REsites.csv")
#pop up info
df1 <- leafletdf %>%
drop_na(Latitude,Longitude) %>%
mutate(popup_info=paste("<b>Site Name</b>:",Site_Name, "<br/>",
"<b>Capacity:</b>",Nameplate_Capacity,"<br/>","<b>Construction Start Year:</b>",
Construction_Start_Year))
#color pallet
colors <- c("orange","blue")
palette <- colorFactor(colours, df1$Fuel_Type)
#time slider
ui <- bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
leafletOutput("map", width = "100%", height = "100%"),
absolutePanel(bottom = 10, right = 10,
textOutput("Counter"),
sliderInput("Year", "Year", min=2000, max=2021, value = 2010, step = 1, sep = "")
)
)
server <- function(input, output, session) {
sliderData <- reactive({
df1 %>%
filter(Construction_Start_Year <= input$Year)
})
output$Counter <- renderText(
paste("Number of sites:", nrow(sliderData()))
)
output$map <- renderLeaflet({
leaflet(ready) %>%
addTiles() %>%
fitBounds(min(df1$Longitude), min(df1$Latitude),
max(df1$Longitude), max(df1$Latitude))
})
observe({
leafletProxy("map", data = sliderData()) %>%
clearMarkers() %>%
addTiles()%>%
addCircleMarkers(lat = ~Latitude, lng = ~Longitude, stroke = 1, fill=1, opacity = 1, radius=~ sqrt(df1$Nameplate_Capacity/2) , popup =~popup_info, color =~ palette(Fuel_Type))
})
}
shinyApp(ui = ui, server = server)
Any help would be massively appreciated, thanks for your time!!