To expand on my comment, let me talk about a similar application I had developed to showcase results of an election. There was some data which was updated periodically in the database (i.e. the Results), while most of the data, including the Geometry did not change.
My JavaScript Application used a static GeoJSON file for the static data and Geometry.
I had a C# windows Service on the Server. It periodically queried the database, and dumped the dynamic parts as a JSON file in the WebServer.
My JavaScript Application, periodically queried for the JSON file with a timestamp attached to the GET request, so that it got the latest data. Once the Ajax call received the data, it changed the symbology of the Vector layer.
Part 2 was developed in this way, instead of a normal web service, to reduce the strain on the database. A conventional service would be hit by all clients, and hence there would be many calls to the database. We wanted to avoid that, and cache this data. Hence we proceded with the architecture given in step 2.
Here's a sample sp-class points data frame in a projected coordinate system like your data is:
> ps
class : SpatialPointsDataFrame
features : 4
extent : 1, 4, 1, 4 (xmin, xmax, ymin, ymax)
crs : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs
variables : 0
If I view it in leaflet, its not in the right place...
> leaflet(ps) %>% addTiles() %>% addMarkers()
and leaflet doesn't complain. But if I convert it to an sf
spatial data frame and use leaflet:
> leaflet(st_as_sf(ps)) %>% addTiles() %>% addMarkers()
Warning messages:
1: sf layer is not long-lat data
2: sf layer has inconsistent datum (+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs).
Need '+proj=longlat +datum=WGS84'
...I get those warnings. This is telling me that leaflet
needs data in lat-long coordinates, so I can transform them to coordinate system 4326:
> leaflet(st_transform(st_as_sf(ps),4326)) %>% addTiles() %>% addMarkers()
and that gets me the points in the right place with no errors.
I don't know why leaflet
doesn't warn with an sp
class object but does with the equivalent sf
object - its another good argument for dropping sp
objects and using sf
as much as possible.
Best Answer
Here is a post I have written regarding how to achieve this, I have covered many things including web-sockets here.
http://yasassriratnayake.blogspot.com/2014/09/developping-web-bases-realtime-updating.html