Upload 4 files
Browse files- .gitattributes +2 -0
- app.R +132 -0
- cas.rds +0 -0
- inland.rds +3 -0
- marine.rds +3 -0
.gitattributes
CHANGED
@@ -32,3 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
inland.rds filter=lfs diff=lfs merge=lfs -text
|
36 |
+
marine.rds filter=lfs diff=lfs merge=lfs -text
|
app.R
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
library(shiny)
|
2 |
+
library(sf)
|
3 |
+
library(stringr)
|
4 |
+
library(dplyr)
|
5 |
+
library(leaflet)
|
6 |
+
|
7 |
+
options(sf_use_s2 = FALSE)
|
8 |
+
|
9 |
+
# Load the shapefiles and data
|
10 |
+
cas <- readRDS("cas.rds")
|
11 |
+
|
12 |
+
inland <- readRDS("inland.rds")
|
13 |
+
marine <- readRDS("marine.rds")
|
14 |
+
|
15 |
+
|
16 |
+
# Example species list
|
17 |
+
species_list <- sort(unique(cas$valid_name))
|
18 |
+
|
19 |
+
|
20 |
+
ui <- fluidPage(
|
21 |
+
titlePanel("Global fish distribution across biogeographic realm"),
|
22 |
+
tags$head(tags$style(HTML("
|
23 |
+
body { background-color: #f2f2f2; color: #333333; }
|
24 |
+
.well { background-color: #ffffff; border: none; }
|
25 |
+
#map { height: 100vh; } /* Set the map to take the full viewport height */
|
26 |
+
#controls {
|
27 |
+
background-color: rgba(255, 255, 255, 0.3);
|
28 |
+
padding: 15px;
|
29 |
+
border-radius: 8px;
|
30 |
+
}
|
31 |
+
"))),
|
32 |
+
fluidRow(
|
33 |
+
column(2, # Left side navigation panel (20% of the width)
|
34 |
+
div(id = "controls", class = "panel panel-default",
|
35 |
+
fixed = FALSE, draggable = TRUE,
|
36 |
+
width = "100%", height = "100vh",
|
37 |
+
#img(src = "path_to_logo.png", height = "100px"), # Replace with actual logo path
|
38 |
+
selectizeInput("species",
|
39 |
+
HTML(paste0("Choose/Input a species (<span style='color:red;'>", scales::comma(nrow(cas)), "</span>):")),
|
40 |
+
choices = NULL,
|
41 |
+
selected = NULL),
|
42 |
+
actionButton("run", "Run", class = "btn-primary")
|
43 |
+
),
|
44 |
+
div(
|
45 |
+
tags$h5(HTML("<strong>Acknowledgements</strong>:")),
|
46 |
+
tags$p(HTML("<small>Heartfelt thanks to the hundreds of taxonomists for their selfless dedication. Data source (updated June 2024): <a href='http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatmain.asp' target='_blank'> Eschmeyer's Catalog of Fishes</a>.</small>"))
|
47 |
+
),
|
48 |
+
div(
|
49 |
+
tags$h5(HTML("<strong>References</strong>:")),
|
50 |
+
tags$p(HTML("<small>[1]Fricke R, Eschmeyer WN, Van der Laan R.(2024). <a href='http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatmain.asp' ",
|
51 |
+
"target='_blank'>Catalog of fishes: genera, species, references </a>. California Academy of Sciences, San Francisco, CA, USA.</small>")),
|
52 |
+
tags$p(HTML("<small>[2]Costello MJ, Tsai P, Wong PS, Cheung AKL, Basher Z, Chaudhary C.(2017). Marine biogeographic realms and species endemicity. <em>Nature Communications</em>, 8(1), 1057. </small>")),
|
53 |
+
tags$p(HTML("<small>[3]Tedesco PA, Beauchard O, Bigorne R, Blanchet S, Buisson L, Conti L, Cornu J,Dias MS, Grenouillet G, Hugueny B, Jézéquel C, Leprieur F, Brosse S, Oberdorff T.(2017). A global database on freshwater fish species occurrence in drainage basins. <em>Scientific Data</em>, 4(1), 1-6.</small>"))
|
54 |
+
),
|
55 |
+
tags$map(HTML(paste0(
|
56 |
+
'<script type="text/javascript" id="clstr_globe" src="//clustrmaps.com/globe.js?d=fcrVhJisR3nagD85u6uUHpeDl2frZFCBy5i5BhDcpss"></script>'
|
57 |
+
))),
|
58 |
+
),
|
59 |
+
column(10, # Right side map panel (80% of the width)
|
60 |
+
leafletOutput("map", width = "100%", height = "100vh")
|
61 |
+
)
|
62 |
+
)
|
63 |
+
)
|
64 |
+
|
65 |
+
|
66 |
+
# Server logic
|
67 |
+
server <- function(input, output, session) {
|
68 |
+
|
69 |
+
# Update selectize input with species list (server-side)
|
70 |
+
updateSelectizeInput(session, "species",
|
71 |
+
choices = species_list,
|
72 |
+
server = TRUE)
|
73 |
+
|
74 |
+
observeEvent(input$run, {
|
75 |
+
sp <- input$species
|
76 |
+
|
77 |
+
realm <- cas %>%
|
78 |
+
dplyr::filter(valid_name %in% sp) %>%
|
79 |
+
dplyr::select(biogeographic_realm) %>%
|
80 |
+
str_split(";") %>%
|
81 |
+
unlist()
|
82 |
+
|
83 |
+
|
84 |
+
# Create map with Leaflet
|
85 |
+
output$map <- renderLeaflet({
|
86 |
+
leaflet() %>%
|
87 |
+
addProviderTiles("OpenStreetMap.Mapnik") %>%
|
88 |
+
addPolygons(data = marine[which(marine$name %in% realm),],
|
89 |
+
fillColor = "#00A8E6", fillOpacity = 0.5, color = NA, group = "Marine") %>%
|
90 |
+
addPolygons(data = inland[which(inland$BasinName %in% realm),],
|
91 |
+
fillColor = "#EEB134", fillOpacity = 0.5, color = NA, group = "Inland") %>%
|
92 |
+
#setView(lng = 0, lat = 20, zoom = 2) %>%
|
93 |
+
addControl(
|
94 |
+
html = paste(
|
95 |
+
"<strong>Data Source (Updated 2024-06): ",
|
96 |
+
"<a href='http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatmain.asp' ",
|
97 |
+
"target='_blank'>Eschmeyer's Catalog of Fishes</a></strong><br>",
|
98 |
+
"<small>Feel free to contact: <a href='mailto:[email protected]'>[email protected]</a></small>"
|
99 |
+
),
|
100 |
+
position = "bottomright",
|
101 |
+
className = "leaflet-control-custom"
|
102 |
+
)
|
103 |
+
})
|
104 |
+
})
|
105 |
+
|
106 |
+
# Add a popup showing species name and biogeographic realm on map click
|
107 |
+
observeEvent(input$map_click, {
|
108 |
+
click <- input$map_click
|
109 |
+
if (is.null(click))
|
110 |
+
return()
|
111 |
+
|
112 |
+
# Extract the species Latin name and realm for popup
|
113 |
+
sp <- input$species
|
114 |
+
habitat <- cas %>%
|
115 |
+
dplyr::filter(valid_name %in% sp) %>%
|
116 |
+
dplyr::select(habitat)
|
117 |
+
|
118 |
+
leafletProxy("map") %>%
|
119 |
+
clearPopups() %>%
|
120 |
+
addPopups(
|
121 |
+
lng = click$lng, lat = click$lat,
|
122 |
+
popup = paste0(
|
123 |
+
"<strong>Species: </strong>", "<em>", sp, "</em>",
|
124 |
+
"<br><strong>Habitat: </strong>", habitat
|
125 |
+
)
|
126 |
+
)
|
127 |
+
})
|
128 |
+
|
129 |
+
}
|
130 |
+
|
131 |
+
# Run the app
|
132 |
+
shinyApp(ui, server)
|
cas.rds
ADDED
Binary file (612 kB). View file
|
|
inland.rds
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b2b7b5ad27b1f0f55070d16823e58ef5c0c0acdd02e7b16c3db3acf3d96e8228
|
3 |
+
size 35522091
|
marine.rds
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a170833dbc772067f0bb7a8adb72d3fbf14367861679e0950b6e533f4ae07fc5
|
3 |
+
size 19635509
|