I have a Shiny app which among other functionalities, allows the user to click on a leaflet map,captue the lat lon as the coordinates of a ship, feed in the course and speed and pass this information on to a radar simulator over a socket. Given the course and speed of the ship,I need to pass on the updated coordinates to the radar simulator every second. Presumably, invalidateLater()
is what I need after reading through this. But somehow I just can't wrap my head around the functioning of invalidateLater()
. This is what I have unsuccessfully tried so far:
#Reactive values to hold the lat lon of the map_click event
rvs <- reactiveValues()
observe({
req(rvs$own_ship_lat)
invalidateLater(1000)
#Data to be passed to the simulator
df <- data.frame(Type='Platform',ID='Own_Ship',Lat = rvs$own_ship_lat,
Lon = rvs$own_ship_lon,
Alt=10.5, LandReflect = 10,
Course=input$own_course,
Speed=input$own_speed)
#Convert the data to json format
jdata <- jsonlite::toJSON(df)
#Function to make a socket connection and pass on the json data to the simulator
sendDRS(jdata)
#Calculate next point to be passed on to the simulator
next_pt <- geosphere::destPoint(c(rvs$own_ship_lon, rvs$own_ship_lat),
input$own_course, input$own_speed)
isolate(rvs$own_ship_lat <- next_pt[2])
isolate(rvs$own_ship_lon <- next_pt[1])
# print(next_pt)
})
rvs$own_ship_lat
and rvs$own_ship_lon
hold the lat lon values of the mouseclick on the leaflet map. If I uncomment the the print(next_pt)
, it infinitely prints the first rightly calculated next_pt
values.