|
library(shiny)
|
|
library(sf)
|
|
library(stringr)
|
|
library(dplyr)
|
|
library(leaflet)
|
|
|
|
options(sf_use_s2 = FALSE)
|
|
|
|
|
|
cas <- readRDS("cas.rds")
|
|
|
|
inland <- readRDS("inland.rds")
|
|
marine <- readRDS("marine.rds")
|
|
|
|
|
|
|
|
species_list <- sort(unique(cas$valid_name))
|
|
|
|
|
|
ui <- fluidPage(
|
|
titlePanel("Global fish distribution across biogeographic realm"),
|
|
tags$head(tags$style(HTML("
|
|
body { background-color: #f2f2f2; color: #333333; }
|
|
.well { background-color: #ffffff; border: none; }
|
|
#map { height: 100vh; } /* Set the map to take the full viewport height */
|
|
#controls {
|
|
background-color: rgba(255, 255, 255, 0.3);
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
}
|
|
"))),
|
|
fluidRow(
|
|
column(2,
|
|
div(id = "controls", class = "panel panel-default",
|
|
fixed = FALSE, draggable = TRUE,
|
|
width = "100%", height = "100vh",
|
|
|
|
selectizeInput("species",
|
|
HTML(paste0("Choose/Input a species (<span style='color:red;'>", scales::comma(nrow(cas)), "</span>):")),
|
|
choices = NULL,
|
|
selected = NULL),
|
|
actionButton("run", "Run", class = "btn-primary")
|
|
),
|
|
div(
|
|
tags$h5(HTML("<strong>Acknowledgements</strong>:")),
|
|
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>"))
|
|
),
|
|
div(
|
|
tags$h5(HTML("<strong>References</strong>:")),
|
|
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' ",
|
|
"target='_blank'>Catalog of fishes: genera, species, references </a>. California Academy of Sciences, San Francisco, CA, USA.</small>")),
|
|
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>")),
|
|
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>"))
|
|
),
|
|
tags$map(HTML(paste0(
|
|
'<script type="text/javascript" id="clstr_globe" src="//clustrmaps.com/globe.js?d=fcrVhJisR3nagD85u6uUHpeDl2frZFCBy5i5BhDcpss"></script>'
|
|
))),
|
|
),
|
|
column(10,
|
|
leafletOutput("map", width = "100%", height = "100vh")
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
|
|
server <- function(input, output, session) {
|
|
|
|
|
|
updateSelectizeInput(session, "species",
|
|
choices = species_list,
|
|
server = TRUE)
|
|
|
|
observeEvent(input$run, {
|
|
sp <- input$species
|
|
|
|
realm <- cas %>%
|
|
dplyr::filter(valid_name %in% sp) %>%
|
|
dplyr::select(biogeographic_realm) %>%
|
|
str_split(";") %>%
|
|
unlist()
|
|
|
|
|
|
|
|
output$map <- renderLeaflet({
|
|
leaflet() %>%
|
|
addProviderTiles("OpenStreetMap.Mapnik") %>%
|
|
addPolygons(data = marine[which(marine$name %in% realm),],
|
|
fillColor = "#00A8E6", fillOpacity = 0.5, color = NA, group = "Marine") %>%
|
|
addPolygons(data = inland[which(inland$BasinName %in% realm),],
|
|
fillColor = "#EEB134", fillOpacity = 0.5, color = NA, group = "Inland") %>%
|
|
|
|
addControl(
|
|
html = paste(
|
|
"<strong>Data Source (Updated 2024-06): ",
|
|
"<a href='http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatmain.asp' ",
|
|
"target='_blank'>Eschmeyer's Catalog of Fishes</a></strong><br>",
|
|
"<small>Feel free to contact: <a href='mailto:[email protected]'>[email protected]</a></small>"
|
|
),
|
|
position = "bottomright",
|
|
className = "leaflet-control-custom"
|
|
)
|
|
})
|
|
})
|
|
|
|
|
|
observeEvent(input$map_click, {
|
|
click <- input$map_click
|
|
if (is.null(click))
|
|
return()
|
|
|
|
|
|
sp <- input$species
|
|
habitat <- cas %>%
|
|
dplyr::filter(valid_name %in% sp) %>%
|
|
dplyr::select(habitat)
|
|
|
|
leafletProxy("map") %>%
|
|
clearPopups() %>%
|
|
addPopups(
|
|
lng = click$lng, lat = click$lat,
|
|
popup = paste0(
|
|
"<strong>Species: </strong>", "<em>", sp, "</em>",
|
|
"<br><strong>Habitat: </strong>", habitat
|
|
)
|
|
)
|
|
})
|
|
|
|
}
|
|
|
|
|
|
shinyApp(ui, server)
|
|
|