Spaces:
Sleeping
Sleeping
wait for button press
Browse files- app.R +14 -9
- inat-ranges.R +30 -12
app.R
CHANGED
@@ -32,19 +32,24 @@ ui <- page_sidebar(
|
|
32 |
)
|
33 |
|
34 |
server <- function(input, output, session) {
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
m <- richness_map(url, aoi)
|
39 |
-
m
|
40 |
})
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
aoi <- get_division(input$location)
|
45 |
richness(inat, aoi, rank = input$rank, taxon = input$taxon)
|
|
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
})
|
49 |
}
|
50 |
|
|
|
32 |
)
|
33 |
|
34 |
server <- function(input, output, session) {
|
35 |
+
# Create reactive expressions that only trigger when button is clicked
|
36 |
+
aoi_reactive <- eventReactive(input$button, {
|
37 |
+
get_division(input$location)
|
|
|
|
|
38 |
})
|
39 |
|
40 |
+
url_reactive <- eventReactive(input$button, {
|
41 |
+
aoi <- aoi_reactive()
|
|
|
42 |
richness(inat, aoi, rank = input$rank, taxon = input$taxon)
|
43 |
+
})
|
44 |
|
45 |
+
output$map <- renderMaplibre({
|
46 |
+
# This will only render when button is clicked
|
47 |
+
url <- url_reactive()
|
48 |
+
aoi <- aoi_reactive()
|
49 |
+
|
50 |
+
print(url)
|
51 |
+
m <- richness_map(url, aoi)
|
52 |
+
m
|
53 |
})
|
54 |
}
|
55 |
|
inat-ranges.R
CHANGED
@@ -3,8 +3,6 @@ library(duckdbfs)
|
|
3 |
library(mapgl)
|
4 |
library(glue)
|
5 |
|
6 |
-
fs::dir_create(overture:::overture_cache())
|
7 |
-
|
8 |
public_endpoint <- Sys.getenv(
|
9 |
"AWS_PUBLIC_ENDPOINT",
|
10 |
Sys.getenv("AWS_S3_ENDPOINT")
|
@@ -13,15 +11,31 @@ public_endpoint <- Sys.getenv(
|
|
13 |
|
14 |
duckdbfs::duckdb_secrets()
|
15 |
inat <- open_dataset("s3://public-inat/hex")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
taxa <- open_dataset(
|
17 |
glue("s3://public-inat/taxonomy/taxa.parquet"),
|
18 |
recursive = FALSE
|
19 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
taxa <-
|
22 |
-
"s3://public-inat/taxonomy/taxa.parquet",
|
23 |
-
recursive = FALSE
|
24 |
-
)
|
25 |
|
26 |
get_hash <- function(aoi, rank, taxon) {
|
27 |
digest::digest(list(aoi, rank, taxon))
|
@@ -51,12 +65,15 @@ richness <- function(inat, aoi, rank = NULL, taxon = NULL, zoom = 3) {
|
|
51 |
return(url)
|
52 |
}
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# Subset by taxon, if requested
|
55 |
if (!is.null(rank) && !is.null(taxon)) {
|
56 |
-
taxa <- open_dataset(
|
57 |
-
glue("s3://public-inat/taxonomy/taxa.parquet"),
|
58 |
-
recursive = FALSE
|
59 |
-
)
|
60 |
inat <- taxa |>
|
61 |
rename(taxon_id = id) |>
|
62 |
filter(.data[[rank]] == taxon) |>
|
@@ -89,7 +106,8 @@ richness_map <- function(url, gdf) {
|
|
89 |
bounds <- as.vector(sf::st_bbox(gdf))
|
90 |
m <-
|
91 |
maplibre() |>
|
92 |
-
add_draw_control() |>
|
|
|
93 |
add_h3j_source("h3j_source", url = url) |>
|
94 |
add_fill_extrusion_layer(
|
95 |
id = "h3j_layer",
|
|
|
3 |
library(mapgl)
|
4 |
library(glue)
|
5 |
|
|
|
|
|
6 |
public_endpoint <- Sys.getenv(
|
7 |
"AWS_PUBLIC_ENDPOINT",
|
8 |
Sys.getenv("AWS_S3_ENDPOINT")
|
|
|
11 |
|
12 |
duckdbfs::duckdb_secrets()
|
13 |
inat <- open_dataset("s3://public-inat/hex")
|
14 |
+
|
15 |
+
common <- open_dataset(
|
16 |
+
"s3://public-inat/taxonomy/vernacular/VernacularNames-english.csv",
|
17 |
+
format = 'csv',
|
18 |
+
recursive = FALSE
|
19 |
+
) |>
|
20 |
+
select(id, vernacularName)
|
21 |
taxa <- open_dataset(
|
22 |
glue("s3://public-inat/taxonomy/taxa.parquet"),
|
23 |
recursive = FALSE
|
24 |
+
) |>
|
25 |
+
select(
|
26 |
+
"id",
|
27 |
+
"scientificName",
|
28 |
+
"kingdom",
|
29 |
+
"phylum",
|
30 |
+
"class",
|
31 |
+
"order",
|
32 |
+
"family",
|
33 |
+
"genus",
|
34 |
+
"specificEpithet",
|
35 |
+
"infraspecificEpithet"
|
36 |
+
)
|
37 |
|
38 |
+
taxa <- common |> inner_join(taxa)
|
|
|
|
|
|
|
39 |
|
40 |
get_hash <- function(aoi, rank, taxon) {
|
41 |
digest::digest(list(aoi, rank, taxon))
|
|
|
65 |
return(url)
|
66 |
}
|
67 |
|
68 |
+
if (rank == "" || rank == "NULL") {
|
69 |
+
rank <- NULL
|
70 |
+
}
|
71 |
+
if (taxon == "" || taxon == "NULL") {
|
72 |
+
taxon <- NULL
|
73 |
+
}
|
74 |
+
|
75 |
# Subset by taxon, if requested
|
76 |
if (!is.null(rank) && !is.null(taxon)) {
|
|
|
|
|
|
|
|
|
77 |
inat <- taxa |>
|
78 |
rename(taxon_id = id) |>
|
79 |
filter(.data[[rank]] == taxon) |>
|
|
|
106 |
bounds <- as.vector(sf::st_bbox(gdf))
|
107 |
m <-
|
108 |
maplibre() |>
|
109 |
+
# add_draw_control() |>
|
110 |
+
add_geocoder_control() |>
|
111 |
add_h3j_source("h3j_source", url = url) |>
|
112 |
add_fill_extrusion_layer(
|
113 |
id = "h3j_layer",
|