Hello,
I am trying to make the intersection between different circles happen on a leaflet map taking into consideration the different variables. For instance, if I when I click Andrew_XXXXX and Monday, I just want to see the circle of Andrew on a Monday. If I want Andy_YYYY on a Tuesday, I want to only see Andy on a Tuesday and if I want both Andrew and Andy on a Monday, I want only Andrew and Andy on a Monday. I used leaflet before and now this is my first attempt at making leaflet connect with Shiny.
However, I still can't make the intersection to happen.
I posted a question earlier to explain what I am trying to do.
Would you please help if you can ? Thank you..
This is my code:
## Data
Latitude = c(33.79053,34.31533,21.44848,33.89115)
Longitude = c(-84.0348,-83.8166,-158.003, -117.295)
Worker = c('A','A','B','B')
Max.Distance.from.C.or.HB = c(35,55,75,100)
Manager = c('Andrew_XXXXX','Andrew_XXXXX','Andy_YYYY', 'Andy_YYYY')
Days = c('Tuesday','Monday','Monday','Tuesday')
coverage_data <- data.frame(Latitude,Longitude,Worker, Max.Distance.from.C.or.HB, Manager,
Days)
# Convert to miles
coverage_data <- coverage_data %>%
mutate(Radius = coverage_data$Max.Distance.from.C.or.HB * 1609.34)
ui <- bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
leafletOutput("map", width = "100%", height = "100%"),
absolutePanel(top = 10, right = 10,
radioButtons(inputId = "Days", label = "Days:",
choices = c("Monday" = "Monday",
"Tuesday" = "Tuesday"
)),
radioButtons(inputId = "Manager", label = "Manager:",
choices = c("Andrew_XXXXX" = "Andrew_XXXXX",
"Andy_YYYY" = "Andy_YYYY"
))
))
server <- shinyServer(function(input, output) {
DaysInput <- reactive({
switch(input$Days,
"Monday" = Monday,
"Tuesday" = Tuesday)
})
ManagerInput <- reactive({
switch(input$Manager,
"Andrew_XXXXX" = Andrew_XXXXX,
"Andy_YYYY" = Andy_YYYY)
})
output$map <- renderLeaflet({
leaflet(coverage_data) %>%
setView(lng = -95.7129, lat = 34.0902, zoom = 4.499) %>%
addProviderTiles(providers$OpenStreetMap.France) %>%
addCircles(lng = coverage_data$Longitude,
lat = coverage_data$Latitude,
#color = ~pal(coverage_data$Worker),
weight = 1,
radius = coverage_data$Radius,
opacity = 0.5,
#label = lapply(coverage_data$label, HTML),
fillOpacity = 0.55)
})
})
shinyApp(ui,server)