Last active
February 18, 2022 05:28
-
-
Save tts/924b764e7607db5d0a57 to your computer and use it in GitHub Desktop.
Finnish Breeding Bird Atlas (1-2) open data as a Shiny web app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| library(leaflet) | |
| library(shinythemes) | |
| library(dplyr) | |
| # See http://tuijasonkkila.fi/blog/2015/03/birds-on-a-map/ | |
| # http://atlas3.lintuatlas.fi/taustaa/kaytto | |
| # | |
| # linnut <- read.table("lajit.csv", sep = ",", stringsAsFactors = F, quote = "") | |
| # names(linnut) <- c("lyhenne", "latina", "suomi", "ruotsi", "englanti", "julkisuus") | |
| # | |
| # ruudut <- read.table("ruudut.csv", sep = ",", stringsAsFactors = F, quote = "") | |
| # names(ruudut) <- c("N", "E", "selvitysaste1", "selvitysaste2", "selvitys12") | |
| # | |
| # http://www.luomus.fi/fi/tietotekniikkapalvelut | |
| # coord <- read.table("allcoord.csv", header = F, sep = ",", quote = "", stringsAsFactors = F) | |
| # | |
| # cd <- coord %>% | |
| # mutate(N = V2, E = V3, lat = V5, lon = V6) %>% | |
| # select(N, E, lat, lon) | |
| # | |
| # havainnot <- read.table("havainnot.csv", sep = ",", stringsAsFactors = F, quote = "") | |
| # names(havainnot) <- c("lyhenne", "N", "E", "varmuus1", "varmuus2", "varmuus12") | |
| # | |
| # lintuhavainnot <- left_join(linnut, havainnot, by = "lyhenne") | |
| # | |
| # data <- inner_join(lintuhavainnot, cd, by = c("N" = "N", "E" = "E")) | |
| # | |
| # 4 Blues from ColorBrewer | |
| # data$color <- sapply(data$varmuus12, function(x) { | |
| # if (x == 2) "#a1dab4" | |
| # else if (x == 3) "#41b6c4" | |
| # else if (x == 4) "#225ea8" | |
| # else "#ffffcc" | |
| #}) | |
| # | |
| # | |
| # write.table(data, file = "birds.csv", sep = ";", row.names = F) | |
| data <- read.table(file = "birds.csv", sep = ";", header = T, stringsAsFactors = F) | |
| data$ruotsi <- sapply(data$ruotsi, function(x) iconv(x, from = "ISO-8859-1", to = "UTF-8")) | |
| data$suomi <- sapply(data$suomi, function(x) iconv(x, from = "ISO-8859-1", to = "UTF-8")) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shinyServer(function(input, output, session) { | |
| observe({ | |
| updateSelectizeInput(session, 'birds', choices = c("", unique(data[[input$lan]]))) | |
| }) | |
| birds <- reactive({ | |
| if( is.null(input$birds) ) | |
| return() | |
| data[data[[isolate(input$lan)]] == input$birds, ] | |
| }) | |
| output$leaflet <- renderLeaflet({ | |
| m <- leaflet(birds()) | |
| m %>% | |
| addTiles() %>% | |
| setView(27.6473941, 66.682128, zoom = 3.5) %>% | |
| addCircleMarkers(lat = ~lat, lng = ~lon, | |
| color = ~color, | |
| clusterOptions = markerClusterOptions()) | |
| }) | |
| output$species <- renderText({ | |
| validate( | |
| need(input$birds, 'Nothing to show yet') | |
| ) | |
| paste(birds()$suomi[1], | |
| birds()$ruotsi[1], | |
| birds()$englanti[1], | |
| birds()$latina[1], | |
| birds()$lyhenne[1], | |
| sep = "<br/>") | |
| }) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shinyUI(fluidPage( | |
| theme = shinytheme("cosmo"), | |
| titlePanel("Finnish Breeding Bird Atlas"), | |
| sidebarLayout( | |
| sidebarPanel( | |
| br(), | |
| selectInput(inputId = "lan", | |
| label = "Language:", | |
| choices = c("Finnish" = "suomi", | |
| "Swedish" = "ruotsi", | |
| "English" = "englanti", | |
| "Latin" = "latina", | |
| "Acronym" = "lyhenne"), | |
| selected = "englanti" | |
| ), | |
| br(), | |
| selectizeInput( | |
| inputId = "birds", | |
| label = "Select species", | |
| multiple = F, | |
| choices = c("", unique(data[["englanti"]])) | |
| ), | |
| br(), | |
| p("First, select language (or acronym) and then species"), | |
| br(), | |
| p("The darker blue the circle, the bigger the certainty that the species was breeding in that grid"), | |
| br(), | |
| HTML("Results of the 1st and 2nd Finnish bird atlas. Finnish Museum of Natural History, University of Helsinki. Used with Creative Commons Attribution 3.0 -license") | |
| ), | |
| mainPanel( | |
| tabsetPanel( | |
| tabPanel("Map", | |
| leafletOutput("leaflet", height = 800), | |
| br(), | |
| htmlOutput("species")) | |
| ) | |
| ) | |
| ) | |
| )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment