title: display map just once (leaflet and shiny)
body: <p>I am new to Shiny, I have gps data and would like to display it nicely on a map. I need to do an animation that depends on time - basically, track an individual over time on a map. The problem that I am facing here is that when I click on the time slider to run (animation) the map reloads every time there is a new point in time. I would like the map to be loaded only once when I open the app and the points appear as time goes by for a selected userid. I hope this is clear. </p>
  
  <pre><code>library(shiny)
  library(leaflet)
  library(lubridate)
  library(shinydashboard)
  library(tidyverse)
  
  latitude=c(37.4218, 37.4063)
  longitude=c(-124.0831, -124.1190)
  userid=c(1704, 1704)
  time=c("2017-09-15 14:40:58", "2017-09-15 14:53:35")
  
  ## reproducible data 
  geo&lt;- as.data.frame(cbind(latitude,
          longitude, 
          userid, 
          time))
  
  ## data manipulation
  geo&lt;- geo %&gt;% 
  mutate(time = ymd_hms(time))%&gt;% 
  mutate(longitude=as.numeric(longitude), 
       latitude=as.numeric(latitude), 
       userid=as.numeric(userid))
  
  
  region&lt;- "US" ##"US" / "Boston" select region of initial view
  
  if (region=="US") {
    lngset = -93.85
    latset = 37.45
    zoomset = 4
  }
  if (region=="Boston") {
    lngset = ## update
    latset = ## update
    zoomset = ## update
  }
  
  mindate&lt;-min(geo$time)
  maxdate&lt;-max(geo$time)
  
  IDS&lt;-unique(geo$userid)
  
  ui=fluidPage(
     titlePanel("title"),
     leafletOutput("mymap",height = 500),
     selectInput(inputId = "userid", 
            label="user id", 
            choices = IDS),
      sliderInput("date_range", 
            "Choose Date:", 
            min = mindate, 
            max = maxdate, 
            step = 1, ## by minute 
            value = mindate,
            animate = animationOptions(loop = TRUE, interval = 1000))
  )
  
  
  
  
  server &lt;- function(input,output){
  
   display only location for an hour for a chosen used
   data &lt;- reactive({
     x &lt;- geo %&gt;% ## 
       filter(time&lt;=input$date_range &amp; time&gt;=input$date_range-hours(1), 
  userid==input$userid)
   })
  
  
    output$mymap &lt;- renderLeaflet({
     df &lt;- data()
  
      m &lt;- leaflet(data = df) %&gt;%
       setView(lng = lngset, lat = latset, zoom = zoomset) %&gt;% ## center 
       addTiles() %&gt;%
       addCircles(lng = ~longitude,
                  lat = ~latitude,
                   popup = paste("User", df$userid, "&lt;br&gt;",
                                "Year:", df$time))
      m
  
  
    })
  
  
  
  }
  
  ## deploy the app
  shinyApp(ui=ui, server=server)
  </code></pre>