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

Improved Graph

The color bar for points in the graph changes adjusts to the selected date range.
parent a418b0ad
No related branches found
Tags v0.1
No related merge requests found
......@@ -191,29 +191,34 @@ server <- function(input, output, session) {
## 3. Plot salinity profile for selected point ------------------------------
### Create a reactive function to compute color scale limits
### based on the selected date range
color_scale_limits <- reactive({
min_date <- min(filteredData()$Date)
max_date <- max(filteredData()$Date)
return(c(min_date, max_date))
})
### When a point is selected on the map, display the salinity profile(s)
observeEvent(input$myMap_marker_click, {
event <- input$myMap_marker_click
df <- filteredData() %>%
filter(Station_ID == event$id)
output$selected_id <- renderText({
paste("Selected Location: ", event$id)
})
output$graph <- renderPlotly(
plot_ly(data = df, x = ~Value, y = ~(-1*Depth),
type = 'scatter', mode = 'markers', text = ~Date, colors = "viridis",
marker = list(size = 5, color = ~Date, colors = "viridis")) %>%
layout(
title = "Salinity profile plot",
xaxis = list(title = "Salinity (PSU)"),
yaxis = list(title = "Depth (m)")
)
)
profile_plot <- filteredData() %>%
filter(Station_ID == event$id) %>%
mutate(Depth = -1*Depth) %>%
ggplot() +
geom_point(
mapping = aes(x = Value, y = Depth, color = Date),
show.legend = FALSE) +
scale_color_gradient(
low = "gold", high = "maroon",
limits = color_scale_limits()) +
labs(x = "Salinity (PSU)", y = "Depth (m)") +
theme(legend.position = "none")
output$graph <- renderPlotly(ggplotly(profile_plot))
})
}
# Initialize App ===============================================================
......
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