I want to create a map with a sidebar where you can select the range of a time period. The idea is that the map shows marks only for hotels which opened during the period. I had no clue to do that so I tried to use selectInput instead since it seemed a little easier for me. But it seems I still can't make it work. Any guidance would be appreciated.
Here's the sample data frame:
Hotel Year lat long
A 2000 41.886337 -87.628472
B 2005 41.88819 -87.635199
C 2010 41.891113 -87.63301
Here's the ui.R:
#ui.R
library(shiny)
library(leaflet)
shinyUI(fluidPage(
titlePanel("Hotel Map"),
sidebarLayout(
sidebarPanel(
selectInput("year",
label = "Choose Year:",
choices = c(2000,2005,2010),
selected = 2000
)),
mainPanel (leafletOutput("map","100%",300))
)
))
Here's the server.R:
library(shiny)
library(leaflet)
source("RStudio\\Map-app")
hotels <- read.csv("RStudio\\Map-app\\ChicagoHotels.csv")
shinyServer(
function(input, output) {
output$map <- renderLeaflet({
df <- hotels[hotels$Year == input$year,]
leaflet() %>%
addTiles() %>%
addCircles(data = df)
})
}
)