From a2fb83e2fa174d28bb07039524c57f9578c4a25e Mon Sep 17 00:00:00 2001 From: Geraldine Klarenberg Date: Thu, 27 Jun 2024 14:41:58 -0400 Subject: [PATCH 1/6] Messing around with the CRS in leaflet because I thought it should be changed. But no, it should not. As long as all the points and shapefiles are provided in crs 4326, we're good --- 04_Tests/leaflet_test.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/04_Tests/leaflet_test.R b/04_Tests/leaflet_test.R index 327c117..010b854 100644 --- a/04_Tests/leaflet_test.R +++ b/04_Tests/leaflet_test.R @@ -15,7 +15,17 @@ GTMNERR <- st_read("03_Data_for_app/shapefiles_new/GTMNERR.shp")# CRS: Albers Co GTMNERR <- st_transform(GTMNERR, crs = 4326) -m <- leaflet(data = GTMNERR, options = leafletOptions(minZoom = 9, maxZoom = 18)) %>% +# Leaflet uses EPSG 3857, change this +# https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-web-mapping +epsg4326 <- leafletCRS(crsClass = "L.CRS.EPSG4326") +# BUT! It actually seems that Leaflet does still want shapefiles in 4326, see +# https://github.com/Leaflet/Leaflet/issues/4146 I also tried to change GTMNERR +# to crs 3857 but that threw errors + +m <- leaflet(data = GTMNERR, + options = leafletOptions(#crs = epsg4326, + minZoom = 9, + maxZoom = 18)) %>% #setView(lng=-81.347388, lat=30.075, zoom = 11) %>% clearBounds() %>% addTiles() %>% # Add default OpenStreetMap map tiles @@ -32,7 +42,7 @@ HAB_data_locations <- HAB_data %>% distinct() %>% st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326) -leaflet(options = leafletOptions(minZoom = 9, maxZoom = 18)) %>% +leaflet(options = leafletOptions(crs = epsg4326, minZoom = 9, maxZoom = 18)) %>% setView(lng=-81.347388, lat=30.075, zoom = 11) %>% # Base map addTiles() %>% # Add default OpenStreetMap map tiles From 666119ea87d2f2d3ce36533d2c474ba4518d36bf Mon Sep 17 00:00:00 2001 From: Geraldine Klarenberg Date: Thu, 27 Jun 2024 14:43:23 -0400 Subject: [PATCH 2/6] Added another link with info about the crs in leaflet --- 04_Tests/leaflet_test.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/04_Tests/leaflet_test.R b/04_Tests/leaflet_test.R index 010b854..c125916 100644 --- a/04_Tests/leaflet_test.R +++ b/04_Tests/leaflet_test.R @@ -20,7 +20,8 @@ GTMNERR <- st_transform(GTMNERR, crs = 4326) epsg4326 <- leafletCRS(crsClass = "L.CRS.EPSG4326") # BUT! It actually seems that Leaflet does still want shapefiles in 4326, see # https://github.com/Leaflet/Leaflet/issues/4146 I also tried to change GTMNERR -# to crs 3857 but that threw errors +# to crs 3857 but that threw errors. See second paragraph here: +# https://rstudio.github.io/leaflet/articles/projections.html m <- leaflet(data = GTMNERR, options = leafletOptions(#crs = epsg4326, From 64d713a2aa8da6eb55bbe05d1d62a62e258a6bb2 Mon Sep 17 00:00:00 2001 From: Geraldine Klarenberg Date: Thu, 27 Jun 2024 16:18:59 -0400 Subject: [PATCH 3/6] Added shapefiles for HUC10, HUC12, salt marshes, mangroves, ofw to the main page --- 02_Cleaning_scripts/shapefile_cleanup.R | 9 ++++----- global.R | 23 ++++++++++++++++++----- modules/main_page.R | 25 ++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/02_Cleaning_scripts/shapefile_cleanup.R b/02_Cleaning_scripts/shapefile_cleanup.R index f2f7991..cf99b63 100644 --- a/02_Cleaning_scripts/shapefile_cleanup.R +++ b/02_Cleaning_scripts/shapefile_cleanup.R @@ -55,7 +55,7 @@ pt4 <- st_point(c(xmax, ymax)) # Put together as sf object and get bounding box bound_box <- st_bbox(st_sfc(pt1, pt3, pt4, pt2, crs = st_crs(GTMNERR))) -##### Counties ##### +#### Counties ##### counties <- st_read("01_Data_raw/shapefiles/countyshore_areas_sep15/countyshore_areas_sep15.shp") # CRS: Albers Conical Equal Area counties <- st_transform(counties, crs = st_crs(GTMNERR)) @@ -79,7 +79,7 @@ st_write(counties_select, "03_Data_for_app/shapefiles_new/counties_GTMNERR.shp", append = FALSE) # Ignore warnings when writing data: checked saved shapefile and it is correct -##### Salt marshes ##### +#### Salt marshes ##### salt_marsh <- st_read("01_Data_raw/shapefiles/salt_marsh_2020/salt_marsh_2020.shp") # CRS: NAD83(HARN) / Florida GDL Albers -> for visualization this is not a problem, # for consistency I am still changing the CRS @@ -95,7 +95,7 @@ ggplot()+ st_write(salt_marsh, "03_Data_for_app/shapefiles_new/salt_marsh_GTMNERR.shp", append = FALSE) -##### Hydrology (several shapefiles) ##### +#### Hydrology (several shapefiles) ##### hydro_6 <- st_read("01_Data_raw/shapefiles/nhdwbd_huc6_dec17/nhdwbd_huc6_dec17.shp") # CRS: Albers Conical Equal Area hydro_6 <- st_transform(hydro_6, crs = st_crs(GTMNERR)) @@ -159,8 +159,7 @@ ggplot()+ # Look up differences between HUCs to add to metadata st_write(hydro_10_select, "03_Data_for_app/shapefiles_new/nhdwbd_huc10_dec17_GTMNERR.shp", append = FALSE) st_write(hydro_12_select, "03_Data_for_app/shapefiles_new/nhdwbd_huc12_dec17_GTMNERR.shp", append = FALSE) -#### CHECK WARNINGS of some values not being written (too long) ##### - +#### Checked warnings of some values not being written (too long): looks fine #### Water bodies #### waterbodies <- st_read("01_Data_raw/shapefiles/nhd24waterbody_dec17/nhd24waterbody_dec17.shp") diff --git a/global.R b/global.R index ba70b3d..ab8c38a 100644 --- a/global.R +++ b/global.R @@ -40,10 +40,23 @@ try({ print(paste0("Working dir: ", getwd())) }, silent = FALSE) # Setting silent = FALSE will print the error message to the console -#### GTMNERR shapefile ------------------------------------------------ -GTMNERR <- st_read("./03_Data_for_app/shapefiles_new/GTMNERR.shp") -GTMNERR <- st_transform(GTMNERR, crs = 4326) +### Load shapefiles ------------------------------------------------ -#### county shapefiles ------------------------------------------------ +##### GTMNERR shapefile ------------------------------------------------ +GTMNERR <- st_read("./03_Data_for_app/shapefiles_new/GTMNERR_small_nosea.shp") + +##### county shapefiles ------------------------------------------------ counties_select <- st_read("./03_Data_for_app/shapefiles_new/counties_GTMNERR.shp") -counties_select <- st_transform(counties_select, crs = 4326) + +##### HUC shapefiles ------------------------------------------------ +HUC10 <- st_read("./03_Data_for_app/shapefiles_new/nhdwbd_huc10_dec17_GTMNERR.shp") +HUC12 <- st_read("./03_Data_for_app/shapefiles_new/nhdwbd_huc12_dec17_GTMNERR.shp") + +##### Outstanding Florida Waters (OFW) shapefiles ------------------------------ +ofw <- st_read("./03_Data_for_app/shapefiles_new/ofw_GTMNERR.shp") + +##### mangrove shapefiles ----------------------------------------------------- +mangroves <- st_read("./03_Data_for_app/shapefiles_new/mangrove_GTMNERR.shp") + +##### salt marsh shapefiles ----------------------------------------------------- +saltmarsh <- st_read("./03_Data_for_app/shapefiles_new/salt_marsh_GTMNERR.shp") diff --git a/modules/main_page.R b/modules/main_page.R index 23b9b1b..d28f4e9 100644 --- a/modules/main_page.R +++ b/modules/main_page.R @@ -55,6 +55,26 @@ mainPageServer <- function(input, output, session) { highlightOptions = highlightOptions(color = "white", weight = 2, bringToFront = TRUE), group = "Counties", popup = ~NAME) %>% + addPolygons(data = mangroves, + color = "darkgreen", weight = 2, opacity = 1, + fill = TRUE, fillColor = "darkgreen", fillOpacity = 0.4, + group = "Mangroves") %>% #, popup = ~Area_ha + addPolygons(data = ofw, + color = "darkorange", weight = 2, opacity = 1, + fill = TRUE, fillColor = "darkorange", fillOpacity = 0.4, + group = "Outstanding Florida Waters") %>% + addPolygons(data = saltmarsh, + color = "darkslateblue", weight = 2, opacity = 1, + fill = TRUE, fillColor = "darkslateblue", fillOpacity = 0.4, + group = "Salt marshes") %>% + addPolygons(data = HUC10, + color = "royalblue", weight = 2, opacity = 1, + fill = TRUE, fillColor = "royalblue", fillOpacity = 0.2, + group = "HUC10", popup = ~NAME) %>% + addPolygons(data = HUC12, + color = "darkblue", weight = 2, opacity = 1, + fill = TRUE, fillColor = "darkblue", fillOpacity = 0.2, + group = "HUC12", popup = ~NAME) %>% # addMarkers(data = HAB_data_locations, # popup = ~paste("Site: ", Site, "
", # "County: ", County), @@ -66,7 +86,10 @@ mainPageServer <- function(input, output, session) { "Sampling start year: ", minYear, "% # # Layers control (turning layers on and off) - addLayersControl(overlayGroups = c("Counties", "GTMNERR boundaries", "WQ"), + addLayersControl(overlayGroups = c("Counties", "GTMNERR boundaries", + "WQ", "Mangroves", "Salt marshes", + "Outstanding Florida Waters", "HUC10", + "HUC12"), options = layersControlOptions(collapsed = FALSE)) %>% addMeasure(primaryLengthUnit = "miles", primaryAreaUnit = "sqmiles") }) From 9e5fb3e04ce1c36eb8877c1d2b22fc18ee8d005d Mon Sep 17 00:00:00 2001 From: Geraldine Klarenberg Date: Thu, 27 Jun 2024 18:04:48 -0400 Subject: [PATCH 4/6] Updated WQ cleaning script outputs to also have a column "dataset" added to it --- 02_Cleaning_scripts/WQ_GTMNERR.R | 3 ++- 03_Data_for_app/WQ_locations.Rds | Bin 810 -> 858 bytes 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/02_Cleaning_scripts/WQ_GTMNERR.R b/02_Cleaning_scripts/WQ_GTMNERR.R index 36e33e4..430e630 100644 --- a/02_Cleaning_scripts/WQ_GTMNERR.R +++ b/02_Cleaning_scripts/WQ_GTMNERR.R @@ -79,7 +79,8 @@ WQ_locations <- WQ %>% mutate(Year = year(SampleDate)) %>% select(site_friendly, Year, site_acronym, lat, long, wbid, location) %>% group_by(site_friendly, site_acronym, lat, long, wbid, location) %>% - summarize(maxYear = max(Year), minYear = min(Year)) + summarize(maxYear = max(Year), minYear = min(Year)) %>% + mutate(dataset = "Guana Water Quality Monitoring (GTMNERR)") WQ_data_available <- WQ %>% mutate(Year = year(SampleDate)) %>% diff --git a/03_Data_for_app/WQ_locations.Rds b/03_Data_for_app/WQ_locations.Rds index 8a6868da5a97922093b6a8c1c0ba1607e3daaf5f..57c1747578234aabe22845cb62e5426fd598601e 100644 GIT binary patch literal 858 zcmV-g1Eu^QiwFP!000001MOB%Xwy&_PusLx+jUlC7eOck$0k_VA8||;0y4|6Ev(C& z!dS_gYzs@1nxyNBmx3O~^x{qfojd4JQ1q}OD!n+x=|MpzDtPg-lc>m;y4IKUz4k4n z;NM#VFW>L?d*6Hc^1YWY@3e;?2nRuu;O+#FaE>r14)+4K4-hwKe$adbY2c<%nw8i< zn4RGRoltAWwcrs8&n^qku8JqFc3Y0`ftt6h#e`X2fszlCDiQ4xyU}1{s))dGA`c~x zAq~rEZ5k?#5g{=n@`{QEmFI}c3UJw-3P&i6p63Lx5;)Mis(SS`0qMq_&`a4vv5FY$ ztU?sGJshc^VT2+l5sF3i6zXx&R9kL&aOgZuwH|!EvFxF#1NnQ8{p&Qf|58hMDNa-V zzTy0bJWY8o-aOlMm+miJ$rKJ1X^M>4`WCO#{X5@|7snQ9s)c?wx4A`At`_F|n+=-k zXd~qN=V;3Lfc^S#96hhVjQZC*#;+BaQ>(e2qd$xg9 zLIb@Y3k>sq?DOC_uv`4j!dqZ3zla`t4*EaM>|J{a_>V{VcOzil=BM*FUID(%-|^;5 zc_;Nn)3;^`T$Y+uA6x@`>(nOrkXjfH*d3ckPVrJa!)itk9)(p;ZI6Ge_zV(H$dabW z;%|s(W361(3j;x~EJ17LX8q4>^?CEAdClCcUodgAZf#AA*Iup~qk0MgLupnNv}_6JGKrGf#_pkf^l|Mn+fxit^l7z^rD%^}D`iiF%Ii2FUI5!Cumo_0* znFBE7%CQ<7oK)B(Z<^Vy$eEx7bk*4A;BS!wH&AlEm_tBLdI)Y*3{*km6$QzRE+!>x#DpZhgs=txSYo;h& zMov_CG;tC2qe=Z}Qa_s1KAISxi4Qg#YzW&i?7%RIVJC)N7;eCDBZl1=_F&kH;U*0G z%w;I0Wm7zKAj+M#5=^oKeL=GcO;O{bplWd$l|xTi)bEu_1RQ`Z)|lqk%c;FYSXNI5 kn$q(&70Ym_h#Rm@i7eJV4O~Px&Sh+q4@EGJ;3$=@xTbe2ry2@3$`&l#mQVt zgqsvvIA>RB)+Hg(Dmx?{fjH1P*#X{AYHT*`BV0AtRlub zs*uEOk3=hIkf7)Zf?@-u6qe#bY+H7z|KtV4w(ftkzT`vfzTEvM!8OG0z1$pGOdvMc zJDB^JL#+SOt#gg{P+#$CCV!xSSZCDMyKn>bZGS&n7+yeZGkQL=v58oBbNt8Kb;P!} zG0KDUh;=>WzC9Wt@5{$e2iMw1uIJ;YRx2*N;rTmH=kxKQ+bbKpw!o_4 zV?Cep@%V?~Fa0B6H-+u_cVMr)960g<=08vFUVR1p=i}V_A=tO++1$<7z_*0E{;VnQ z&Qj69dW-P0)U4)k4d|m&pU_L{VZ5L=HlLCfzE)}s3|d~q*38ZN-`VQ>=1lvVxmmwx;%432LP72Du#t);B~H_DMV%y@1 z7Wf1|h84FyDpi>S7;)t}oePbrTuLzQ>{XRaNCsUq&I)|BS$II{znViJPNfh$q$rxG z3yCpR6l7kSCGF7=xumMdvndjb#OdUuN{T#AaAs8GNq>`+B&UmtjCn(fn>j0RYK4lj zL2JWu8%faco#1A6?u4B?VdqY$e@`GTgCx~e54QPUF&>3_bmSbA1k4>*7=)Y<0u`=`Cg oShh Date: Thu, 27 Jun 2024 18:05:38 -0400 Subject: [PATCH 5/6] Updated the main page a whole bunch: it is showing more shapefiles now, and there is a dropdown menu you can use for getting markers for different datasets --- modules/main_page.R | 106 +++++++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 30 deletions(-) diff --git a/modules/main_page.R b/modules/main_page.R index d28f4e9..15b3b3f 100644 --- a/modules/main_page.R +++ b/modules/main_page.R @@ -1,17 +1,52 @@ + +#### Get WIN data locations +# I am putting this here right now, but I feel we should move this to a cleaning +# script so it doesn't need to be run every time someone uses the app (as with +# WQ locations) +WIN_df <- readRDS("./03_Data_for_app/WIN.Rds") + +WIN_data_locations = WIN_df %>% + filter(variable %in% c("geometry", + "HUC12.Name", + "Start.Date", + "latitude", + "longitude") + ) %>% + select(c(RowID, variable, value)) %>% + distinct(RowID, variable, value) %>% + pivot_wider( + names_from = variable, + values_from = value, + values_fill = list(value = NA) + ) %>% + distinct(geometry, HUC12.Name, Start.Date, latitude, longitude) %>% + mutate( + lat = as.numeric(latitude), + long = as.numeric(longitude), + dataset = "Watershed Information Network (DEP)" + ) %>% + select(-geometry, - latitude, -longitude) + +#### WQ locations data ------------------------------------------------ +WQ_data_locations <- readRDS("./03_Data_for_app/WQ_locations.Rds") + +# For now, for testing, make WQ_locations the dataframe to be used for filtering +datasets_location <- full_join(WQ_data_locations, WIN_data_locations) +datasets_location <- st_as_sf(datasets_location, coords = c("long", "lat"), crs = 4326) + +### Define the UI ------------------------------------------------------------- mainPageUI <- function(id) { ns <- NS(id) # This is an important part to add to all subpages so they use the # correct sessions / ID's that connect the ui and server here tagList( h2("Main Page"), p("This is the main page of the Guana River Data Dashboard."), + # Dropdown menu for markers is above the map fluidRow( - # Map occupies 1st column - column(width = 10, leafletOutput(ns("map"), height=750)), - # histogram occupies rows in the 2nd column - # column(width = 5, plotOutput(ns("distPlot")), - # sliderInput(ns("bins"), "Number of bins:", - # min = 1, max = 50, value = 30) - # ) + column(width = 7, uiOutput(ns("dropdown_ui"))), + ), + fluidRow( + column(width = 10, leafletOutput(ns("map"), height="500px")), ), # fluidRow( # column(12, @@ -21,24 +56,28 @@ mainPageUI <- function(id) { ) } +### Define the server logic ---------------------------------------------------- mainPageServer <- function(input, output, session) { ns <- session$ns - # Create the histogram - # output$distPlot <- renderPlot({ - # # generate bins based on input$bins from ui.R - # x <- filter(WQ, ComponentShort == "ATEMP") %>% select(Result) %>% pull() - # x <- as.numeric(x) # stop-gap measure because everything is characters - # bins <- seq(min(x, na.rm = TRUE), max(x, na.rm = TRUE), - # length.out = input$bins + 1) - # - # # draw the histogram with the specified number of bins - # hist(x, breaks = bins, col = 'darkgray', border = 'white', - # xlab = 'Air temperature (degrees Celsius)', - # main = 'Histogram of air temperatures') + # Reactive value for the selected dataset + # selected_dataset <- reactive({ + # print(paste("Selected dataset changed to:", input$dataset_selector)) + # input$dataset # }) + # Create the dropdown UI + output$dropdown_ui <- renderUI({ + print("Rendering dropdown UI") + selectInput( + inputId = ns("dataset_selector"), + label = "Select a dataset", + choices = unique(datasets_location$dataset), + selected = unique(datasets_location$dataset)[1] + ) + }) + # Create the map output$map <- renderLeaflet({ leaflet(options = leafletOptions(minZoom = 9, maxZoom = 18)) %>% @@ -75,17 +114,7 @@ mainPageServer <- function(input, output, session) { color = "darkblue", weight = 2, opacity = 1, fill = TRUE, fillColor = "darkblue", fillOpacity = 0.2, group = "HUC12", popup = ~NAME) %>% - # addMarkers(data = HAB_data_locations, - # popup = ~paste("Site: ", Site, "
", - # "County: ", County), - # group = "HAB") %>% - addMarkers(data = WQ_data_locations, - popup = ~paste("Station: ", site_friendly, "
", - "Location: ", wbid, "
", - "Latest year of sampling: ", maxYear, "% - # # Layers control (turning layers on and off) + # Layers control (turning layers on and off) addLayersControl(overlayGroups = c("Counties", "GTMNERR boundaries", "WQ", "Mangroves", "Salt marshes", "Outstanding Florida Waters", "HUC10", @@ -94,6 +123,23 @@ mainPageServer <- function(input, output, session) { addMeasure(primaryLengthUnit = "miles", primaryAreaUnit = "sqmiles") }) + # Select dataset to add markers to the plot + observeEvent(input$dataset_selector, { + # Filter data based on selected group + filtered_data <- datasets_location[datasets_location$dataset == input$dataset_selector,] + + # Add markers to the map - commented out the popup bc this only works for WQ data + print("Adding markers") + leafletProxy(ns("map")) %>% + clearMarkers() %>% + addMarkers( + data = filtered_data, + # popup = ~paste("Station: ", site_friendly, "
", + # "Location: ", wbid, "
", + # "Latest year of sampling: ", maxYear, " Date: Thu, 27 Jun 2024 21:05:21 -0400 Subject: [PATCH 6/6] Updated the main page so it shows data types (not datasets). Updated WQ code so it adds a column "type". Only shows water quality for now. --- 02_Cleaning_scripts/WQ_GTMNERR.R | 3 ++- 03_Data_for_app/WQ_locations.Rds | Bin 858 -> 875 bytes modules/main_page.R | 39 ++++++++++++++++++------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/02_Cleaning_scripts/WQ_GTMNERR.R b/02_Cleaning_scripts/WQ_GTMNERR.R index 430e630..4010ff2 100644 --- a/02_Cleaning_scripts/WQ_GTMNERR.R +++ b/02_Cleaning_scripts/WQ_GTMNERR.R @@ -80,7 +80,8 @@ WQ_locations <- WQ %>% select(site_friendly, Year, site_acronym, lat, long, wbid, location) %>% group_by(site_friendly, site_acronym, lat, long, wbid, location) %>% summarize(maxYear = max(Year), minYear = min(Year)) %>% - mutate(dataset = "Guana Water Quality Monitoring (GTMNERR)") + mutate(type = "Water quality", + dataset = "Guana Water Quality Monitoring (GTMNERR)") WQ_data_available <- WQ %>% mutate(Year = year(SampleDate)) %>% diff --git a/03_Data_for_app/WQ_locations.Rds b/03_Data_for_app/WQ_locations.Rds index 57c1747578234aabe22845cb62e5426fd598601e..524f7263cc19ad7f9a6a3ce2a8b1e97538ceb4e4 100644 GIT binary patch delta 855 zcmV-d1E~Dk2I~enABzY80000000Zq-O=#0l98cS{Thn${WEVjw1IH#<*oQbK3jvvB z*cR4hPGPKMZMKD_NtdMShLJfVe~;I`h7|lf*}%*H_y4`$d-=bwf8J>V!!QSiEtH*QCCYYLw(mAL zkIu!oSynPAA3~KQsv^5!W38(QmrU}kK@l1?BxaN;gK3O#iD{mdWY|dWe zp#J0Z-t`y2|Nb!lb{O>A^km`sOW^OYw>>%2yyNPk0qZV-$C9(Ee>2tq-8!`$v`H;& zG^mb^5Ywy>&oYWugGOOhQ(N(O8K36F6QZCMtILKp`)2<4Y~_0k zrhd)7nLlsx&AhcWEuL>g9eiLW!|k@2 zW3l$SzOMfxJ%-zXf8GXDY=UQG+1QLYOmCBtm`StAcyhvET*^3K@f^T|(j=oW!3l{; zv8JBgl9&w&fS0vx4t}FK@B+E`vpEDPQbQo%VUan7jZa7%D|Qc;Vp11fy`GVE7FwX6_8jNM)B35EobGf79>>)S!+|W))M!E^U5f zi4(${jGj~t9^gdj)~7GHlsjnN3a9IID(xBb|JU{!Ho!ZBbY$22f%*HM;rv)M_tbmYLK6yLA17 hBgPVOW8xQiWuvxLKL?>9I2pTgd!&qibeGl>T%IjTW)!9 z=sZoe9(=vA?4hXx`FoH3>om3hQcHL#PE-EA;rxd@O?fZgJlk}a?k`=*6b=<>ij3I$ z7O&I&JKv5M#};X-g?=`-f4N0dt`_F|n+=-kXd~qN=V;3Lfc^S#96hhVjQZC*#;+Ba zQ>(e2qd$xg9LIb@Y3k>sq?DOC_uv`4j!dqZ3zla`t z4*EaM>|J{a_>V{VcOzil=BM*FUID(%-|^;5c_;Nn)3;^`T$Y+ue;-@}eCyOE_>fu{ z4%i)=M^5olJi}^64<3b8Pi>EXtN08OPsoy{$l`B^Xk)Eh)e8ebuPi}p=4SoRZ1s8b zrg_cWtY0v3vufrxZDz;<-3C2^E(%Ay%0KFyzXy8XKHc*d%Y7*{#T#pagW) z*yiAGkpnkSa=w^DKu&rHZd43ZLF40-ioi>pm_@&3Lu3<*EM=1@7LnCZg%o9J3gOIz zz@h)DC?{A=kR`|)lI+|Wo>eMTkZ`KMk;-ePC|yQQRCqLTe-ZVgN&RS2Kbq7&ni!vn z4>lWY2-`92z%YqnCx%@ZZoqIOhTRzUVAzY{CJg(`WhkX(Q#^Da%AK|nOtJ%gL9+=> zQRAYZYH=BrLr+=M@0Cgf9Dps>nC92Zsl7y4R!;|-()Aw-rZWg?w`$H$kW=IoOfFi` QqTYT2kKANs1jY>j03B|RqyPW_ diff --git a/modules/main_page.R b/modules/main_page.R index 15b3b3f..f35ec56 100644 --- a/modules/main_page.R +++ b/modules/main_page.R @@ -23,6 +23,7 @@ WIN_data_locations = WIN_df %>% mutate( lat = as.numeric(latitude), long = as.numeric(longitude), + type = "Water quality", dataset = "Watershed Information Network (DEP)" ) %>% select(-geometry, - latitude, -longitude) @@ -34,6 +35,9 @@ WQ_data_locations <- readRDS("./03_Data_for_app/WQ_locations.Rds") datasets_location <- full_join(WQ_data_locations, WIN_data_locations) datasets_location <- st_as_sf(datasets_location, coords = c("long", "lat"), crs = 4326) +color_palette <- colorFactor(palette = c("red"), #, "blue", "green", "purple" + domain = datasets_location$type) + ### Define the UI ------------------------------------------------------------- mainPageUI <- function(id) { ns <- NS(id) # This is an important part to add to all subpages so they use the @@ -61,20 +65,14 @@ mainPageUI <- function(id) { mainPageServer <- function(input, output, session) { ns <- session$ns - # Reactive value for the selected dataset - # selected_dataset <- reactive({ - # print(paste("Selected dataset changed to:", input$dataset_selector)) - # input$dataset - # }) - # Create the dropdown UI output$dropdown_ui <- renderUI({ print("Rendering dropdown UI") selectInput( - inputId = ns("dataset_selector"), - label = "Select a dataset", - choices = unique(datasets_location$dataset), - selected = unique(datasets_location$dataset)[1] + inputId = ns("datatype_selector"), + label = "Select a type of data to see locations with data availability", + choices = unique(datasets_location$type), + selected = unique(datasets_location$type)[1] ) }) @@ -115,25 +113,34 @@ mainPageServer <- function(input, output, session) { fill = TRUE, fillColor = "darkblue", fillOpacity = 0.2, group = "HUC12", popup = ~NAME) %>% # Layers control (turning layers on and off) - addLayersControl(overlayGroups = c("Counties", "GTMNERR boundaries", - "WQ", "Mangroves", "Salt marshes", + addLayersControl(overlayGroups = c("GTMNERR boundaries", "Counties", + "Mangroves", "Salt marshes", "Outstanding Florida Waters", "HUC10", "HUC12"), - options = layersControlOptions(collapsed = FALSE)) %>% + options = layersControlOptions(collapsed = TRUE)) %>% + hideGroup(c("Counties", "Mangroves", "Salt marshes", + "Outstanding Florida Waters", "HUC10", "HUC12")) %>% addMeasure(primaryLengthUnit = "miles", primaryAreaUnit = "sqmiles") }) # Select dataset to add markers to the plot - observeEvent(input$dataset_selector, { + observeEvent(input$datatype_selector, { # Filter data based on selected group - filtered_data <- datasets_location[datasets_location$dataset == input$dataset_selector,] + filtered_data <- datasets_location[datasets_location$type == input$datatype_selector,] # Add markers to the map - commented out the popup bc this only works for WQ data print("Adding markers") leafletProxy(ns("map")) %>% clearMarkers() %>% - addMarkers( + addCircleMarkers( data = filtered_data, + color = ~color_palette(type), + opacity = 1, + fillOpacity = 0.5, + fillColor = ~color_palette(type), + fill = TRUE, + weight = 3, + radius = 8, # popup = ~paste("Station: ", site_friendly, "
", # "Location: ", wbid, "
", # "Latest year of sampling: ", maxYear, "