'Weekly time series slider not reacting to leaflet in R Shiny

I have a dataframe in R and I am wanting to view as a time series map with the user having the ability to select a week via a slider. The problem is that the leaflet map is not displaying nor is it updating according the slider value.

How can this be fixed?

Code

# This is a Shiny time series map web application
library(shiny)
library(tidyverse)
library(tidyr)
library(leaflet)

# Create date columns
Year = as.numeric(c("2014", "2014", "2014", "2014", "2014"))
Month = as.numeric(c("4", "6", "4", "5", "5"))
Week = as.numeric(c("15", "23", "18", "22", "18"))
ym = c("2014-04-01", "2014-06-01", "2014-04-01",
         "2014-05-01", "2014-05-01")
Start_Date= c("2014-04-09", "2014-06-04", "2014-04-30",
              "2014-05-30", "2014-05-01")
lat = as.numeric(c("45.53814", "45.51076", "45.43560", "45.54332",
        "45.52234"))
lon = as.numeric(c("-73.63672", "-73.61029", "-73.60100",
        "-73.56000 ", "-73.59022"))
id = as.numeric(c("1", "2", "3", "4", "5"))

# Create a df from the above columns
df = data.frame(id, lat, lon, Start_Date, Year, Month,
                   Week, ym)

ui = fluidPage(
    
    # Title
    titlePanel("Time Series Visiualization Map"),

    sidebarLayout(
        
        # Define the sidebar
        sidebarPanel(
            sliderInput("Date", "Week:",
                        min = min(df$Week),
                        max = max(df$Week),
                        value = c(min(df$Week,
                        max(df$Week)),
                        animate = T)
            ),
    ),
    mainPanel(
        leafletOutput("Time_Series_Map"))))
    


# Define server logic required 
server = function(input, output) {
    
    output$Time_Series_Mp = renderLeaflet(
        
        {
            
            
            leaflet(data = df %>% 
                        filter(week >= input$Date[1],
                               week <= input$Date[2])) %>% 
                               addTiles() %>% 
                                   addMarkers(~lon,
                                              ~lat) %>% 
                                   setView(lng = -73.6,
                                           lat = 45.2,
                                           zoom = 12)
        })
}

# Run the application 
shinyApp(ui = ui, server = server)

Current Output

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source