1

The flickering of Shiny leaflet animations has been discussed before (like here), but this was an older post. I have a map with animated points. I've seen similar Shiny apps before that didn't suffer from flickering, but can't seem to resolve this on my end. Any help would be appreciated. A reprex provided below.

library(plyr)
library(dplyr)
library(tidyr)

library(shiny)
library(shinydashboard)
library(leaflet)

data <- data.frame(Date = seq(as.Date("2003-01-15"), as.Date("2003-03-17"), 1)) %>%
        mutate(Lon = -105.57, Lat = 64.86)

ui <- navbarPage(" ", id = "nav", 
 column(width = 4,
        uiOutput("animationSlider")),                   
            fluidRow(column(width = 8, leafletOutput("MapAnimate"))))

        
server <- function(input, output, session) {
    output$animationSlider <- renderUI({
        sliderInput("animationSlider2", "Animation period", 
                 min = min(data$Date), max = max(data$Date), value = min(data$Date), step = 1,
                    animate = animationOptions(interval = 200, loop = FALSE))
                                        })
                                        
    IndividualAnimationPoints <- reactive({
        req(input$animationSlider2)
    
        data %>%
            filter(Date == input$animationSlider2)
                                            })
   
    output$MapAnimate <- renderLeaflet({
            leaflet(data, options = leafletOptions(minZoom = 6)) %>%
                setView(lng = -105.6, lat = 64.86, zoom = 8)  %>%
                addProviderTiles("Esri.WorldImagery", layerId = "basetile",
                    options = providerTileOptions())
                                        }) 
                                    
    observe({
        leafletProxy("MapAnimate", data = IndividualAnimationPoints()) %>%
             clearShapes() %>%
             clearMarkers() %>%
            addCircleMarkers(lng = ~Lon, lat = ~Lat,
                         radius = 5, opacity = 1, fillOpacity = 1, color = "blue") 
              }) 
}


shinyApp(ui = ui, server = server)
user2602640
  • 640
  • 6
  • 21

0 Answers0