I have a working shiny app that sequentially plots locations on a gvisMap based on the date selected on the slider bar. My hope was to create an 'animation' of movement where the user could simply hit the 'play' button on the slider bar and watch the points move across the landscape. However, once I got the code ruing I realized that each time the slider is moved the map refreshes, resulting in a clunky interface. It there a way to plot a single 'base map' that does not refresh every time points are added but maintains the Google-like features (e.g. zoom and mobility)?
My reproducible data are are at the bottom of the script and look like this
> head(dat)
Long Lat PosiGMT LatLong
365 -109.7168 44.66303 2013-05-11 00:00:00 44.6630279694724:-109.716799339033
366 -109.7183 44.66315 2013-05-11 06:00:00 44.6631526844819:-109.718285058244
367 -109.7178 44.66680 2013-05-11 12:00:00 44.6668018103389:-109.717763110702
369 -109.7304 44.67800 2013-05-12 00:00:00 44.6779979605606:-109.730398520879
370 -109.7301 44.67682 2013-05-12 06:00:00 44.6768244249289:-109.730108722209
371 -109.7304 44.67678 2013-05-12 12:00:00 44.6767829303242:-109.730425056581
The ui and server functions are defined below.
library(shiny)
library(googleVis)
ui <- shinyUI(fluidPage(
# Application title
titlePanel("GPS Data Summary"),
sidebarLayout(
# Sidebar with a slider input
sidebarPanel(
sliderInput(inputId = "Date",
label = "Date of Observations",
min = as.Date(min(dat$PosiGMT)), max = as.Date(max(dat$PosiGMT)),
value = as.Date(min(dat$PosiGMT)),
animate = animationOptions(interval=75, loop=T)
)),
# Show a plot of the generated distribution
mainPanel(
#h3(textOutput("year")),
htmlOutput("gvis")
)
)
))
server <- function(input, output) {
output$gvis <- renderGvis({
gvisMap(dat[as.Date(dat$PosiGMT) <= input$Date ,], "LatLong",
options=list(showLine=TRUE, enableScrollWheel=TRUE,
mapType='terrain', useMapTypeControl=TRUE,
width="800px", height="800px",
colors = "['#0000ff']",
mapType='hybrid',
icons=paste0("{","'default': {'normal':
'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png',n",
"'selected':'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'",
"}}"),
zoomLevel = 12,
showLine = TRUE
))
})
}
Run the app
shinyApp(ui = ui, server = server)
Notice each time the slider bar is moved the map refreshes.
While not included here, I have also tried to get the same outcome using the ggmap package but came to the same issue of slow response time resulting from the iterative map reloading.
Any suggestions on how to more efficiently and seamlessly sequentially plot GPS locations would be greatly appreciated.
dat <- structure(list(Long = c(-109.716799339033, -109.718285058244,
-109.717763110702, -109.730398520879, -109.730108722209, -109.730425056581,
-109.741800876548, -109.734654659708, -109.743624300483, -109.757095672106,
-109.76369389675, -109.769584371753, -109.789292897871, -109.789342976355,
-109.793547755157, -109.803630701798), Lat = c(44.6630279694724,
44.6631526844819, 44.6668018103389, 44.6779979605606, 44.6768244249289,
44.6767829303242, 44.6764227097723, 44.6720135852281, 44.6761186995206,
44.6751048104976, 44.673934104023, 44.6728094065928, 44.672110819562,
44.6721293553387, 44.6689149795185, 44.6699843203283), PosiGMT = structure(c(1368252000,
1368273600, 1368295200, 1368338400, 1368360000, 1368381600, 1368424800,
1368446400, 1368468000, 1368511200, 1368532800, 1368554400, 1368576000,
1368597600, 1368619200, 1368640800), class = c("POSIXct", "POSIXt"
), tzone = ""), LatLong = c("44.6630279694724:-109.716799339033",
"44.6631526844819:-109.718285058244", "44.6668018103389:-109.717763110702",
"44.6779979605606:-109.730398520879", "44.6768244249289:-109.730108722209",
"44.6767829303242:-109.730425056581", "44.6764227097723:-109.741800876548",
"44.6720135852281:-109.734654659708", "44.6761186995206:-109.743624300483",
"44.6751048104976:-109.757095672106", "44.673934104023:-109.76369389675",
"44.6728094065928:-109.769584371753", "44.672110819562:-109.789292897871",
"44.6721293553387:-109.789342976355", "44.6689149795185:-109.793547755157",
"44.6699843203283:-109.803630701798")), .Names = c("Long", "Lat",
"PosiGMT", "LatLong"), row.names = c("365", "366", "367", "369",
"370", "371", "373", "374", "375", "377", "378", "379", "380",
"381", "382", "383"), class = "data.frame")
