Spaces:
Runtime error
Runtime error
demo
Browse files
app.R
CHANGED
@@ -3,29 +3,86 @@ library(bslib)
|
|
3 |
library(mapgl)
|
4 |
|
5 |
pmtiles <- "https://data.source.coop/cboettig/us-boundaries/mappinginequality.pmtiles"
|
|
|
|
|
6 |
ui <- page_sidebar(
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
)
|
13 |
-
)
|
14 |
|
|
|
15 |
server <- function(input, output, session) {
|
16 |
output$map <- renderMaplibre({
|
17 |
|
18 |
-
maplibre(center=c(-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
})
|
27 |
|
28 |
|
29 |
}
|
30 |
|
31 |
-
|
|
|
|
3 |
library(mapgl)
|
4 |
|
5 |
pmtiles <- "https://data.source.coop/cboettig/us-boundaries/mappinginequality.pmtiles"
|
6 |
+
|
7 |
+
# Define the UI
|
8 |
ui <- page_sidebar(
|
9 |
+
|
10 |
+
titlePanel("Demo App"),
|
11 |
+
sidebar = sidebar(
|
12 |
+
input_switch("redlines", "Redlined Areas"),
|
13 |
+
input_switch("svi", "Social Vulnerability", value = TRUE),
|
14 |
+
input_switch("richness", "Biodiversity Richness"),
|
15 |
+
input_switch("rsr", "Biodiversity Range Size Rarity"),
|
16 |
+
|
17 |
+
),
|
18 |
+
# Create a main panel
|
19 |
+
card(full_screen = TRUE,
|
20 |
+
maplibreOutput("map")
|
21 |
+
|
22 |
+
)
|
23 |
)
|
|
|
24 |
|
25 |
+
# Define the server
|
26 |
server <- function(input, output, session) {
|
27 |
output$map <- renderMaplibre({
|
28 |
|
29 |
+
m <- maplibre(center=c(-92.9, 41.3), zoom=4)
|
30 |
+
|
31 |
+
if (input$redlines) {
|
32 |
+
m <- m |>
|
33 |
+
add_fill_layer(
|
34 |
+
id = "redlines",
|
35 |
+
source = list(type = "vector",
|
36 |
+
url = paste0("pmtiles://", pmtiles)),
|
37 |
+
source_layer = "mappinginequality",
|
38 |
+
fill_color = list("get", "fill")
|
39 |
+
)
|
40 |
+
}
|
41 |
+
if (input$richness) {
|
42 |
+
m <- m |>
|
43 |
+
add_raster_source(id = "richness",
|
44 |
+
tiles = "https://data.source.coop/cboettig/mobi/tiles/red/species-richness-all/{z}/{x}/{y}.png",
|
45 |
+
maxzoom = 11
|
46 |
+
) |>
|
47 |
+
add_raster_layer(id = "richness-layer",
|
48 |
+
source = "richness")
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
if (input$rsr) {
|
53 |
+
m <- m |>
|
54 |
+
add_raster_source(id = "rsr",
|
55 |
+
tiles = "https://data.source.coop/cboettig/mobi/tiles/green/range-size-rarity-all/{z}/{x}/{y}.png",
|
56 |
+
maxzoom = 11
|
57 |
+
) |>
|
58 |
+
add_raster_layer(id = "richness-layer",
|
59 |
+
source = "rsr")
|
60 |
+
|
61 |
+
}
|
62 |
+
if (input$svi) {
|
63 |
+
m <- m |>
|
64 |
+
add_fill_layer(
|
65 |
+
id = "redlines",
|
66 |
+
source = list(type = "vector",
|
67 |
+
url = paste0("pmtiles://", "https://data.source.coop/cboettig/social-vulnerability/svi2020_us_tract.pmtiles")),
|
68 |
+
source_layer = "SVI2000_US_tract",
|
69 |
+
fill_opacity = 0.5,
|
70 |
+
fill_color = interpolate(column = "RPL_THEMES",
|
71 |
+
values = c(0, 1),
|
72 |
+
stops = c("lightblue", "darkblue"),
|
73 |
+
na_color = "lightgrey")
|
74 |
+
)
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
m
|
82 |
})
|
83 |
|
84 |
|
85 |
}
|
86 |
|
87 |
+
# Run the app
|
88 |
+
shinyApp(ui = ui, server = server)
|