---
title: "Interactive Shiny dashboard template file (with web data)"
author: "DVE 2026"
format: dashboard
server: shiny
theme: sketchy
---

```{r}
#| context: setup
library(ggplot2)
library(viridis)
library(DT)
dat <- read.csv(url("https://raw.githubusercontent.com/seanteachesmath/data/refs/heads/main/inat-brief.csv"), header = TRUE, sep = ",")
tab <- table(dat$common_name)
nms <- names(tab)
owls <- nms[grep("Owl", nms)]
dat <- dat[dat$common_name %in% owls, ]
dat$common_name <- factor(dat$common_name)
dat$color <- as.numeric(dat$common_name)

```

#  {.sidebar}

This dashboard uses a subset of Oklahoma County [iNaturalist](https://inaturalist.org) observation data to illustrate the spatial distribution of observations.

I am using the "sketchy" theme to lighten the mood - and to illustrate that as an option, but you might want something with a more "professional" font.

```{r}
checkboxGroupInput(input = "species", label = "Species", choices = owls, selected = names(tab[tab==max(tab[names(tab) %in% owls])]))
```

# Plot

```{r}
plotOutput("plot")
```

# Data

```{r}
DTOutput("data")
```

```{r}
#| context: server
dash <- reactive({
  dat[dat$common_name %in% input$species, ]
})

output$plot <- renderPlot({
  ggplot(dash(), aes(x = longitude, y = latitude, color = common_name)) + geom_point(size = 3) + xlim(range(dat$longitude)) + ylim(range(dat$latitude)) + labs(x = "Longitude", y = "Latitude") + lims(color = levels(dat$common_name)) 

})

output$data <- renderDT({
  dash()
})
```
