Skip to content

Commit

Permalink
On the main app page, added icons for the menu on the left. Changed w…
Browse files Browse the repository at this point in the history
…in.R to waterquality.R (main script to use for WQ page) and waterquality.R to waterquality2.R (to keep as a back up). made sure app.R refers to the correct pages. Added awesome markers to main_page.R, and changed the zoom level at which the dashboards starts.
  • Loading branch information
gklarenberg committed Aug 20, 2024
1 parent 7194a2e commit 6575650
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 398 deletions.
83 changes: 43 additions & 40 deletions app.R
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
# This is the main app page, which will run and read in all the other pages
# and modules, and render the dashboard

# Note: not necessary to load packages here: this all happens in global.R

source("global.R")
source("functions.R")
source("modules/main_page.R")
source("modules/waterquality.R")
source("modules/algae.R")
source("modules/win.R")

ui <- dashboardPage(
dashboardHeader(title = "Guana River Data Dashboard"),
dashboardSidebar(
sidebarMenu(id = "tabs",
menuItem("Main Page", tabName = "main_page", icon = icon("home")),
menuItem("Water Quality Data", tabName = "waterquality", icon = icon("link")),
menuItem("Harmful Algal Bloom Data", tabName = "algae", icon = icon("link")),
menuItem("Water Information Network", tabName = "win", icon = icon("bridge-water", lib="font-awesome"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "main_page", mainPageUI(id = "main_page")),
tabItem(tabName = "waterquality", WQPageUI(id = "waterquality")),
tabItem(tabName = "algae", HABPageUI(id = "algae")),
tabItem(tabName = "win", WINPageUI(id = "win"))
)
)
)

server <- function(input, output, session) {
moduleServer(module = mainPageServer, id = "main_page", session = session)
WQPageServer("waterquality", parentSession = session)
HABPageServer("algae", parentSession = session)
WINPageServer("win", parentSession = session)
}

shinyApp(ui, server)
# This is the main app page, which will run and read in all the other pages
# and modules, and render the dashboard

# Note: not necessary to load packages here: this all happens in global.R

source("global.R")
source("functions.R")
source("modules/main_page.R")
source("modules/waterquality.R")
source("modules/algae.R")
#source("modules/win.R")

ui <- dashboardPage(
dashboardHeader(title = "Guana River Data Dashboard"),
dashboardSidebar(
sidebarMenu(id = "tabs",
menuItem("Main Page", tabName = "main_page", icon = icon("home")),
#menuItem("Water Quality Data", tabName = "waterquality", icon = icon("link")),
menuItem("Harmful Algal Bloom Data", tabName = "algae", icon = icon("microscope", lib = "font-awesome")),
menuItem("Water Quality Data", tabName = "waterquality", icon = icon("flask-vial", lib="font-awesome")),
menuItem("Water Level Data", tabName = "waterlevel", icon = icon("water", lib="font-awesome")),
menuItem("Fish and Shellfish Data", tabName = "shellfish", icon = icon("fish", lib="font-awesome")),
menuItem("Terrestrial Animal Data", tabName = "animal", icon = icon("paw", lib="font-awesome"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "main_page", mainPageUI(id = "main_page")),
#tabItem(tabName = "waterquality", WQPageUI(id = "waterquality")),
tabItem(tabName = "algae", HABPageUI(id = "algae")),
tabItem(tabName = "waterquality", WINPageUI(id = "waterquality"))
)
)
)

server <- function(input, output, session) {
moduleServer(module = mainPageServer, id = "main_page", session = session)
#WQPageServer("waterquality", parentSession = session)
HABPageServer("algae", parentSession = session)
WINPageServer("waterquality", parentSession = session)
}

shinyApp(ui, server)
65 changes: 36 additions & 29 deletions modules/main_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ 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")
"HUC12Name",
"SampleDate",
"Latitude",
"Longitude")
) %>%
select(c(RowID, variable, value)) %>%
distinct(RowID, variable, value) %>%
Expand All @@ -30,24 +30,28 @@ WIN_data_locations = WIN_df %>%
values_from = value,
values_fill = list(value = NA)
) %>%
distinct(geometry, HUC12.Name, Start.Date, latitude, longitude) %>%
distinct(geometry, HUC12Name, SampleDate, Latitude, Longitude) %>%
mutate(
lat = as.numeric(latitude),
long = as.numeric(longitude),
SampleDate = ymd_hms(SampleDate),
Latitude = as.numeric(Latitude),
Longitude = as.numeric(Longitude),
type = "Water quality",
dataset = "Watershed Information Network (DEP)"
dataset = "Watershed Information Network (DEP)", # Update this so we use data_source
minYear = min(year(SampleDate)),
maxYear = max(year(SampleDate))
) %>%
select(-geometry, - latitude, -longitude)
select(-geometry, -SampleDate)

#### 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)
datasets_location <- st_as_sf(datasets_location, coords = c("Longitude", "Latitude"), crs = 4326)
datasets_location <- datasets_location[!duplicated(datasets_location),]

color_palette <- colorFactor(palette = c("red"), #, "blue", "green", "purple"
domain = datasets_location$type)
color_palette <- colorFactor(palette = c("red", "goldenrod1"), #, "blue", "green"
domain = datasets_location$dataset)

#### HAB locations data ------------------------------------------------
# Add this at some point so there is another dataset that shows up in the dropdown
Expand Down Expand Up @@ -94,8 +98,8 @@ mainPageServer <- function(input, output, session) {
# Create the map
output$map <- renderLeaflet({
leaflet(options = leafletOptions(minZoom = 9, maxZoom = 18)) %>%
#setView(lng=-81.347388, lat=30.075, zoom = 11) %>%
clearBounds() %>% # centers map on all min/max coords
setView(-81.289, lat=29.905, zoom = 10) %>%
#clearBounds() %>% # centers map on all min/max coords
# Base map
addTiles() %>% # Add default OpenStreetMap map tiles
# Polygons, add groups
Expand Down Expand Up @@ -142,25 +146,28 @@ mainPageServer <- function(input, output, session) {
observeEvent(input$datatype_selector, {
# Filter data based on selected group
filtered_data <- datasets_location[datasets_location$type == input$datatype_selector,]

print(filtered_data)
# Add markers to the map - commented out the popup bc this only works for WQ data
print("Adding markers")
leafletProxy(ns("map")) %>%
clearMarkers() %>%
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, "<br>",
# "Location: ", wbid, "<br>",
# "Latest year of sampling: ", maxYear, "<br",
# "Sampling start year: ", minYear, "<br")
)
addAwesomeMarkers(icon = makeAwesomeIcon(icon = "flask", markerColor = "orange", library = "fa",
iconColor = "black"),
data = filtered_data) #%>%
# addCircleMarkers(
# data = filtered_data,
# color = ~color_palette(dataset),
# opacity = 1,
# fillOpacity = 0.5,
# fillColor = ~color_palette(dataset),
# fill = TRUE,
# weight = 3,
# radius = 8,
# popup = ~paste("Station: ", site_friendly, "<br>",
# "Location: ", wbid, "<br>",
# "Latest year of sampling: ", maxYear, "<br",
# "Sampling start year: ", minYear, "<br")
#)
})
# Add buttons to go to other pages
# observeEvent(input[[ns("go_to_subpage")]], {
Expand Down
Loading

0 comments on commit 6575650

Please sign in to comment.