Skip to content
Snippets Groups Projects
Commit e0331805 authored by M. G. Castrellon's avatar M. G. Castrellon
Browse files

Moved filtered points to its own reactive element

parent 3c3912d8
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@ ui <- bootstrapPage(
id = "controls", fixed = TRUE, draggable = FALSE,
top = 20, left = "auto", right = 20, bottom = "auto", width = 400, height = "auto",
### Date Picker
dateInput(inputId = "chosen_date_input",
dateInput(inputId = "date",
label = h4("Select Date (only year and month)"),
value = "2020-01-01", min = "2016-04-01", max = "2023-06-30",
format = "yyyy-mm-dd", startview = "year"),
......@@ -76,7 +76,7 @@ ui <- bootstrapPage(
# Create Server Functionality ==================================================
server <- function(input, output, session) {
## Render leaflet basemap (with no markers)
## 0. Render leaflet basemap -------------------------------------------------
output$myMap <- renderLeaflet({
leaflet(allPoints) %>% addTiles(group = "OSM") %>%
addProviderTiles(providers$Stamen.TonerLite, group = "Toner Lite") %>%
......@@ -88,47 +88,24 @@ server <- function(input, output, session) {
fitBounds(~min(Longitude), ~min(Latitude), ~max(Longitude), ~max(Latitude))
})
## Initiate a 'reactiveValues' object
rctv <- shiny::reactiveValues()
## Start off with no date and no sensor selected
rctv$selected_sensor <- NULL
rctv$selected_date <- NULL
## When a date is selected...
shiny::observe({
### Require that a valid date has been selected
shiny::req(input$chosen_sensor_input != "")
rctv$selected_date <- ymd(input$chosen_date_input)
### Require that a valid sensor has been selected
shiny::req(input$chosen_sensor_input != "")
if (input$chosen_sensor_input == "Salinity") {
rctv$selected_sensor <- "SALT"
}
else if ((input$chosen_sensor_input == "Temperature")) {
rctv$selected_sensor <- "TEMP"
}
### Capture the filtered data based upon the UI selection
rctv$filtered_data <- allData %>%
dplyr::filter(Year == lubridate::year(rctv$selected_date),
Month == lubridate::month(rctv$selected_date),
Sensor == rctv$selected_sensor) %>%
dplyr::collect()
### Extract points to plot from filtered data
rctv$filtered_points <- rctv$filtered_data %>%
## 1. Render points in map ---------------------------------------------------
### Capture the filtered points to plot based upon the UI selection
filtered_points <- reactive({
allData %>%
dplyr::filter(Year == lubridate::year(ymd(input$date)),
Month == lubridate::month(ymd(input$date)),
Sensor == input$sensor) %>%
dplyr::select(Station_ID, Stat_Name, Latitude, Longitude) %>%
dplyr::distinct() %>% data.frame()
dplyr::distinct() %>% dplyr::collect() %>% data.frame()
})
## Plot filtered points on the map
### Plot filtered points on the map
observe({
leafletProxy(mapId = "myMap") %>%
addMarkers(data = rctv$filtered_points, lng = ~Longitude, lat = ~Latitude,
label = ~Station_ID, layerId = ~Station_ID, popup = ~Station_ID)
leafletProxy(mapId = "myMap", data = filtered_points()) %>%
addMarkers(lng = ~Longitude, lat = ~Latitude,
label = ~Station_ID, layerId = ~Station_ID,
popup = ~Station_ID)
})
# output$distPlot <- renderPlot({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment