Otolith commited on
Commit
9d5396a
·
verified ·
1 Parent(s): 0ce5f04

Upload 5 files

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. Dockerfile +29 -0
  3. README.md +3 -3
  4. app.R +132 -0
  5. cas.rds +0 -0
  6. marine.rds +3 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ 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
+ marine.rds filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM rocker/r-base:latest
2
+
3
+ # 设置工作目录
4
+ WORKDIR /code
5
+
6
+ # 安装系统依赖
7
+ RUN apt-get update && apt-get install -y \
8
+ libcurl4-openssl-dev \
9
+ libssl-dev \
10
+ libxml2-dev \
11
+ libgdal-dev \
12
+ libgeos-dev \
13
+ libproj-dev \
14
+ libnetcdf-dev \
15
+ libudunits2-dev \
16
+ && rm -rf /var/lib/apt/lists/*
17
+
18
+ # 安装 R 包
19
+ RUN R -e "install.packages('shiny')" \
20
+ && R -e "install.packages('dplyr')" \
21
+ && R -e "install.packages('sf')" \
22
+ && R -e "install.packages('stringr')" \
23
+ && R -e "install.packages('leaflet')"
24
+
25
+ # 复制应用代码
26
+ COPY . .
27
+
28
+ # 设置容器启动命令
29
+ CMD ["R", "--quiet", "-e", "shiny::runApp(host='0.0.0.0', port=7860)"]
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Fishcas
3
  emoji: 🌍
4
  colorFrom: blue
5
- colorTo: blue
6
  sdk: docker
7
- pinned: true
8
  license: apache-2.0
9
  short_description: Global fish distribution across biogeographic realm
10
  ---
 
1
  ---
2
+ title: Fish Cas
3
  emoji: 🌍
4
  colorFrom: blue
5
+ colorTo: yellow
6
  sdk: docker
7
+ pinned: false
8
  license: apache-2.0
9
  short_description: Global fish distribution across biogeographic realm
10
  ---
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
 
marine.rds ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a170833dbc772067f0bb7a8adb72d3fbf14367861679e0950b6e533f4ae07fc5
3
+ size 19635509