Created
December 4, 2022 21:59
-
-
Save jebyrnes/a58fbda00db5f90d1c6d2c3bb1eacabb to your computer and use it in GitHub Desktop.
A shiny app by chat.openai.com to make clickable maps of all noaa buoys that fetches sea surface temperature.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(rnoaa) | |
library(leaflet) | |
ui <- fluidPage( | |
leafletOutput("map"), | |
plotOutput("tempPlot") | |
) | |
server <- function(input, output) { | |
# Get a list of all available buoys from the rnoaa package | |
buoys <- noaa_buoys() | |
# Create a leaflet map with markers for each buoy | |
output$map <- renderLeaflet({ | |
leaflet() %>% | |
addTiles() %>% | |
addMarkers(data = buoys, lng = ~longitude, lat = ~latitude) | |
}) | |
# When a user clicks on a buoy, fetch the sea surface temperature data | |
# and plot it | |
output$tempPlot <- renderPlot({ | |
# Get the selected buoy | |
buoy <- input$map_marker_click | |
# If a buoy was selected, fetch the sea surface temperature data | |
# and plot it | |
if (!is.null(buoy)) { | |
# Get the sea surface temperature data for the selected buoy | |
tempData <- noaa_water_temperature(buoy$id) | |
# Plot the sea surface temperature over time | |
plot(tempData$date, tempData$water_temperature, type = "l") | |
} | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment