Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created December 4, 2022 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jebyrnes/a58fbda00db5f90d1c6d2c3bb1eacabb to your computer and use it in GitHub Desktop.
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.
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