Spaces:
Sleeping
Sleeping
VICTORY :gem:
Browse files- app.R +14 -26
- inat-ranges.R +10 -15
- test.qmd +34 -0
app.R
CHANGED
@@ -22,6 +22,7 @@ ui <- page_sidebar(
|
|
22 |
textInput("location", "Location", "California"),
|
23 |
varSelectInput("rank", NULL, taxa, selected = "scientificName"),
|
24 |
textInput("taxon", NULL, "Canis lupus"),
|
|
|
25 |
),
|
26 |
card(
|
27 |
full_screen = TRUE,
|
@@ -30,41 +31,28 @@ ui <- page_sidebar(
|
|
30 |
)
|
31 |
|
32 |
server <- function(input, output, session) {
|
33 |
-
# output$map <- renderMaplibre({overture:::map(gdf)})
|
34 |
-
|
35 |
-
observeEvent(input$taxon, {
|
36 |
-
aoi <- get_division(input$location)
|
37 |
-
|
38 |
-
message("Computing richness...")
|
39 |
-
|
40 |
-
meta <- richness(inat, aoi, input$rank, input$taxon)
|
41 |
-
jsonlite::write_json(meta, cache, auto_unbox = TRUE)
|
42 |
-
|
43 |
-
message(paste("rendering", meta$url))
|
44 |
-
|
45 |
-
# session$reload()
|
46 |
-
}) |>
|
47 |
-
debounce(millis = 600)
|
48 |
-
|
49 |
output$map <- renderMaplibre({
|
50 |
if (file.exists(cache)) {
|
51 |
meta <- jsonlite::read_json(cache)
|
52 |
print(meta$url)
|
53 |
} else {
|
54 |
-
|
55 |
-
|
56 |
-
Y = 37,
|
57 |
-
zoom = 4,
|
58 |
-
url = paste0(
|
59 |
-
"https://",
|
60 |
-
public_endpoint,
|
61 |
-
"/public-data/inat-tmp-ranges.h3j"
|
62 |
-
)
|
63 |
-
)
|
64 |
}
|
65 |
m <- richness_map(meta)
|
66 |
m
|
67 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
}
|
69 |
|
70 |
shinyApp(ui, server)
|
|
|
22 |
textInput("location", "Location", "California"),
|
23 |
varSelectInput("rank", NULL, taxa, selected = "scientificName"),
|
24 |
textInput("taxon", NULL, "Canis lupus"),
|
25 |
+
actionButton("button", "Go")
|
26 |
),
|
27 |
card(
|
28 |
full_screen = TRUE,
|
|
|
31 |
)
|
32 |
|
33 |
server <- function(input, output, session) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
output$map <- renderMaplibre({
|
35 |
if (file.exists(cache)) {
|
36 |
meta <- jsonlite::read_json(cache)
|
37 |
print(meta$url)
|
38 |
} else {
|
39 |
+
aoi <- get_division(input$location)
|
40 |
+
meta <- richness(inat, aoi, rank = input$rank, taxon = input$taxon)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
}
|
42 |
m <- richness_map(meta)
|
43 |
m
|
44 |
})
|
45 |
+
|
46 |
+
observeEvent(input$button, {
|
47 |
+
print(input$location)
|
48 |
+
aoi <- get_division(input$location)
|
49 |
+
meta <- richness(inat, aoi, rank = input$rank, taxon = input$taxon)
|
50 |
+
|
51 |
+
jsonlite::write_json(meta, cache, auto_unbox = TRUE)
|
52 |
+
message(paste("rendering", meta$url))
|
53 |
+
|
54 |
+
session$reload()
|
55 |
+
})
|
56 |
}
|
57 |
|
58 |
shinyApp(ui, server)
|
inat-ranges.R
CHANGED
@@ -17,21 +17,10 @@ taxa <- open_dataset(
|
|
17 |
recursive = FALSE
|
18 |
)
|
19 |
|
20 |
-
|
21 |
"s3://public-inat/taxonomy/taxa.parquet",
|
22 |
recursive = FALSE
|
23 |
)
|
24 |
-
common <- duckdbfs::open_dataset(
|
25 |
-
"s3://public-inat/taxonomy/vernacular/VerqnacularNames-english.csv",
|
26 |
-
format = "csv",
|
27 |
-
recursive = FALSE
|
28 |
-
) |>
|
29 |
-
select(id, vernacularName)
|
30 |
-
|
31 |
-
taxa <- left_join(sci, common, by = "id") |>
|
32 |
-
rename(taxon_id = id)
|
33 |
-
|
34 |
-
common_names <- taxa |> pull(vernacularName)
|
35 |
|
36 |
cache <- tempfile(fileext = ".json")
|
37 |
|
@@ -75,6 +64,8 @@ richness <- function(inat, aoi, rank = NULL, taxon = NULL, zoom = 3) {
|
|
75 |
})
|
76 |
|
77 |
center <- c(st_coordinates(st_centroid(st_as_sfc(st_bbox(aoi)))))
|
|
|
|
|
78 |
url <- gsub("s3://", glue("https://{public_endpoint}/"), s3)
|
79 |
|
80 |
meta <- list(
|
@@ -82,14 +73,17 @@ richness <- function(inat, aoi, rank = NULL, taxon = NULL, zoom = 3) {
|
|
82 |
Y = center[2],
|
83 |
zoom = zoom,
|
84 |
url = url,
|
85 |
-
time = clock[[2]]
|
|
|
86 |
)
|
87 |
return(meta)
|
88 |
}
|
89 |
|
90 |
richness_map <- function(meta) {
|
|
|
|
|
91 |
m <-
|
92 |
-
maplibre(
|
93 |
add_draw_control() |>
|
94 |
add_h3j_source("h3j_source", url = meta$url) |>
|
95 |
add_fill_extrusion_layer(
|
@@ -107,7 +101,8 @@ richness_map <- function(meta) {
|
|
107 |
list("*", 100000, list("get", "height"))
|
108 |
),
|
109 |
fill_extrusion_opacity = 0.7
|
110 |
-
)
|
|
|
111 |
|
112 |
return(m)
|
113 |
}
|
|
|
17 |
recursive = FALSE
|
18 |
)
|
19 |
|
20 |
+
taxa <- duckdbfs::open_dataset(
|
21 |
"s3://public-inat/taxonomy/taxa.parquet",
|
22 |
recursive = FALSE
|
23 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
cache <- tempfile(fileext = ".json")
|
26 |
|
|
|
64 |
})
|
65 |
|
66 |
center <- c(st_coordinates(st_centroid(st_as_sfc(st_bbox(aoi)))))
|
67 |
+
bounds <- as.vector(st_bbox(aoi))
|
68 |
+
|
69 |
url <- gsub("s3://", glue("https://{public_endpoint}/"), s3)
|
70 |
|
71 |
meta <- list(
|
|
|
73 |
Y = center[2],
|
74 |
zoom = zoom,
|
75 |
url = url,
|
76 |
+
time = clock[[2]],
|
77 |
+
bounds = bounds
|
78 |
)
|
79 |
return(meta)
|
80 |
}
|
81 |
|
82 |
richness_map <- function(meta) {
|
83 |
+
print(meta)
|
84 |
+
|
85 |
m <-
|
86 |
+
maplibre() |>
|
87 |
add_draw_control() |>
|
88 |
add_h3j_source("h3j_source", url = meta$url) |>
|
89 |
add_fill_extrusion_layer(
|
|
|
101 |
list("*", 100000, list("get", "height"))
|
102 |
),
|
103 |
fill_extrusion_opacity = 0.7
|
104 |
+
) |>
|
105 |
+
fit_bounds(meta$bounds, animate = TRUE)
|
106 |
|
107 |
return(m)
|
108 |
}
|
test.qmd
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
```{r}
|
3 |
+
library(overture)
|
4 |
+
source("utils.R")
|
5 |
+
source("inat-ranges.R")
|
6 |
+
aoi <- get_division("California")
|
7 |
+
|
8 |
+
# gdf <- get_h3_aoi(aoi)
|
9 |
+
|
10 |
+
#inat <- duckdbfs::open_dataset("s3://public-inat/hex")
|
11 |
+
|
12 |
+
rank <- "class"
|
13 |
+
taxon <- "Aves"
|
14 |
+
|
15 |
+
inat <- duckdbfs::open_dataset("s3://public-inat/taxon") |> filter(.data[[rank]] == taxon)
|
16 |
+
|
17 |
+
duckdbfs::open_dataset("s3://public-inat/taxon") |> dplyr::filter(scientificName == "Canis lupus") |> duckdbfs::to_sf()
|
18 |
+
|
19 |
+
class(gdf)
|
20 |
+
overture:::map(gdf)
|
21 |
+
|
22 |
+
|
23 |
+
# filter(.data[[rank]] == taxon) |>
|
24 |
+
# select(taxon_id) |>
|
25 |
+
|
26 |
+
```
|
27 |
+
|
28 |
+
```{r}
|
29 |
+
|
30 |
+
|
31 |
+
inat_range <- inat |> filter(rank == !!taxon)
|
32 |
+
|
33 |
+
print(head(inat_range))
|
34 |
+
```
|