Page 1

Gauge chart and value box on top

Aantal observaties

1220

Craywatch

Row

Number of observations per dataset

Page 2

Column

Observaties per maand

Kaartje

Page 3

Data tabel

---
title: "Chart Multipage"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    source_code: embed
    theme:
      bg: "#101010"
      fg: "#C04384"
---

<!--
---
title: "Multiple pages"
output: 
  flexdashboard::flex_dashboard:
    theme:
      bg: "#101010"
      fg: "#FDF7F7" 
      primary: "#ED79F9"
      base_font:
        google: Prompt
      code_font:
        google: JetBrains Mono
    orientation: rows
    vertical_layout: scroll
runtime: shiny
---
-->

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)      # to do datascience
library(here)           # to work easily with paths
library(sf)             # to work with geospatial vector data
library(leaflet)        # to make dynamic maps
library(DT)             # to make interactive tables
library(flexdashboard)  # to make dashboards
```


```{r dataInput}
# Read data
cray_df <- readr::read_tsv(
  here::here("data", "20250224", "20250224_craywatch_cleaned.txt"),
  na = "",
  guess_max = 10000
)

```

# Page 1

## Gauge chart and value box  on top ####

```{r}
# Number of observations linked to craywatch (via waarnemingen.be)
dataset_name <- "Waarnemingen.be - Non-native animal occurrences in Flanders and the Brussels Capital Region, Belgium"
n_obs_craywatch <- cray_df %>%
  filter(datasetName == dataset_name) %>%
  nrow()
tot_obs <- nrow(cray_df)
percentage_craywatch <- n_obs_craywatch / tot_obs * 100
```

### Aantal observaties

```{r valuebox}
valueBox(n_obs_craywatch, icon = "ion-android-camera")
```


### Craywatch
```{r}
gauge(percentage_craywatch, min = 0, max = 100, symbol = '%')
```


## Row


### Number of observations per dataset

```{r}
cray_df %>%
  count(datasetName) %>%
  mutate(datasetName = reorder(datasetName, n)) %>%
  ggplot(aes(x = datasetName, y = n)) +
    geom_bar(stat = "identity",
             fill = "cornflowerblue") +
    geom_text(aes(label = n), vjust = 0, hjust = 0) +
    scale_x_discrete(label = function(x) stringr::str_trunc(x, 30)) +
    scale_y_continuous(limits = c(0, 1300)) +
    labs(x = "", y = "Number of observations") +
    theme_minimal() +
    coord_flip()
```


# Page 2  {data-orientation=columns}

## Column <!--- {.tabset}--->

### Observaties per maand
    
```{r}
n_obs_per_month_species <-
  cray_df %>%
  count(year, month, species) %>%
  # combine year and month to a single date
  mutate(date = as.Date(paste0(year, "-", month, "-01"))) %>%
  arrange(date, species) %>%
  relocate(date,species, n, everything())
ggplot(n_obs_per_month_species,
       aes(x = date, y = n, fill = species)) +
  geom_bar(stat = 'identity') +
  # Use inferno colors for the species
  scale_fill_viridis_d(option = "inferno") +
  # Add title and labels
  ggtitle("Number of observations per month and species") +
  xlab("Date") + ylab("Number of observations") 
```

### Kaartje

```{r}
cray_fl <- sf::st_as_sf(cray_df,
                        coords = c("decimalLongitude", "decimalLatitude"),
                        crs = 4326)
# Create a palette that maps species to colors
pal <- colorFactor("inferno", cray_fl$species)
leaflet(cray_fl) %>%
  addTiles() %>%
  addCircleMarkers(popup = ~paste0(cray_fl$eventDate, ": ", cray_fl$species),
                   color = pal(cray_fl$species),
                   stroke = FALSE,
                   fillOpacity = 0.5,
                   radius = 4) %>%
  addLegend(pal = pal, values = ~species,
            position = "bottomright")
```

# Page 3

## Data tabel

```{r}
DT::datatable(cray_df)
```