Coder Social home page Coder Social logo

clbenoit / appsilon-homework Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 92 KB

Visualize biodiversity data from the Global Biodiversity Information Facility.

Home Page: https://omicsverse.fr/app/appsilon-homework

R 97.27% SCSS 1.85% JavaScript 0.88%
biology leaflet occurrences photos timeline visualization

appsilon-homework's Introduction

๐ŸŒฟ ๐Ÿ”Ž Biodata Discovery Board App

This app is built with Rhino. You can see a deployed version here: Biodata Discovery Board App Demo. Using the biodiversity data coming from the Global Biodiversity Information Facility, this Shiny app visualizes observed species on the map, draw a timeline with selected species observation, and allows the user to explore associated pictures.

๐Ÿ› ๏ธ Prerequisites

This is an application built in Shiny. To run it, make sure you have R (>= 4.0.0) installed. For JavaScript and Sass development you'll also need Node.js (>= 16.0.0).

๐Ÿ“ฆ Dependencies

Run renv::restore(clean = TRUE) to synchronize the project library with the lockfile when you initially clone the repo or switch branches.

โ–ถ๏ธ Running

To run the app, use Rscript -e 'shiny::runApp(launch.browser = TRUE)'.

๐Ÿ“Š Data

๐Ÿš€ Application-ready data

git-lfs is required to fetch the example dataset

run git lfs pull

Then you'll find it here : inst/extdata/biodiversity_data_poland.db. This dataset is restricted to poland observations to save development time.

๐ŸŒ However, if you want to generate the whole dataset from raw sources.

  1. You can download the whole dataset here.
  2. Then you will have to import occurence and multimedia csv files into an sqlite database
  3. Finally execute these few sqlite queries on your sqlite database :
-- Step 1 : Remove unecessary string in id column 
UPDATE multimedia SET id = REPLACE(id, '@OBS', '')
UPDATE occurence SET id = REPLACE(id, '@OBS', '')

-- Step 2 : Remove unsused columns 
CREATE TABLE occurence_tmp AS
SELECT column1, column2, /* other columns except the one you want to remove */
FROM occurence;
DROP TABLE occurence;
ALTER TABLE occurence_tmp RENAME TO occurence;

-- Step 3 : Convert taxonRank to integer
UPDATE occurence SET taxonRank = REPLACE(taxonRank, 'subspecies', '3');
UPDATE occurence SET taxonRank = REPLACE(taxonRank, 'multispecies', '2');
UPDATE occurence SET taxonRank = REPLACE(taxonRank, 'species', '1');
UPDATE occurence SET taxonRank = REPLACE(taxonRank, 'synonym', '4');
UPDATE occurence SET taxonRank = REPLACE(taxonRank, 'forma', '5');
UPDATE occurence SET taxonRank = REPLACE(taxonRank, 'hybrid', '6');
UPDATE occurence SET taxonRank = REPLACE(taxonRank, 'variety', '7');

-- Step 4 : Split occcurence table by kingdom
PRAGMA foreign_keys=off;
CREATE TABLE IF NOT EXISTS occurence_Fungi AS
SELECT * FROM occurence WHERE 1=0;
INSERT INTO occurence_Fungi
SELECT * FROM occurence WHERE kingdom = 'Fungi';
CREATE TABLE IF NOT EXISTS occurence_Animalia AS
SELECT * FROM occurence WHERE 1=0;
INSERT INTO occurence_Animalia
SELECT * FROM occurence WHERE kingdom = 'Animalia';
CREATE TABLE IF NOT EXISTS occurence_Plantae AS
SELECT * FROM occurence WHERE 1=0;
INSERT INTO occurence_Plantae
SELECT * FROM occurence WHERE kingdom = 'Plantae';

DROP TABLE occurence;
VACUUM;

-- Step 5 : Create species_family_match tables 
CREATE TABLE IF NOT EXISTS species_family_match_Fungi AS
SELECT DISTINCT scientificName, family, taxonRank
FROM occurence_Fungi;
CREATE TABLE IF NOT EXISTS species_family_match_Plantae AS
SELECT DISTINCT scientificName, family, taxonRank
FROM occurence_Plantae;
CREATE TABLE IF NOT EXISTS species_family_match_Animalia AS
SELECT DISTINCT scientificName, family, taxonRank
FROM occurence_Animalia;

-- Step 6 : Create indexes
CREATE INDEX "idx_multimedia_id" ON "multimedia" (
	"id"
);
CREATE INDEX "idx_occurence_Fungi_scientificName" ON "occurence_Fungi" (
	"scientificName"
);
CREATE INDEX "idx_occurence_Plantae_scientificName" ON "occurence_Plantae" (
	"scientificName"
);
CREATE INDEX "idx_occurence_Animalia_scientificName" ON "occurence_Animalia" (
	"scientificName"
);
CREATE INDEX "idx_occurence_Plantae_taxonRank" ON "species_family_match_Plantae" (
	"taxonRank"
);
CREATE INDEX "idx_occurence_Animalia_taxonRank" ON "species_family_match_Animalia" (
	"taxonRank"
);
CREATE INDEX "idx_occurence_Fungi_taxonRank" ON "species_family_match_Fungi" (
	"taxonRank"
);

PRAGMA foreign_keys=on;
-- Step 7 : Commit changes to make them permanent
COMMIT;
VACUUM;
  1. Edit config and .Renviron files to track your database in the app.

appsilon-homework's People

Contributors

clbenoit avatar

Watchers

 avatar

appsilon-homework's Issues

Leafltet clickable markers do not trigger input$MAPID_marker_click when data is reactive

I don"t get why this code works :

box::use(
  reactable,
  shiny[h3, moduleServer, NS, tagList, fluidRow, column,observe,req,icon,
        uiOutput,renderUI,img,observeEvent],
  leaflet[makeIcon,leafletOutput,renderLeaflet,addTiles,setView,addProviderTiles,addMarkers,leaflet],
  dplyr[`%>%`,filter],
)
#' @export
ui <- function(id) {
  ns <- NS(id)
  tagList(
    fluidRow(column(width = 12,
            leafletOutput(outputId = ns("leafletMap")),
            uiOutput(ns("imageOutput"))
    ))
  )
}

#' @export
server <- function(id, data, session) {
  moduleServer(id, function(input, output, session) {

    data <- data.frame(
       id = c(1, 2, 3),
       latitudeDecimal = c(51.505, 51.51, 51.52),
       longitudeDecimal = c(-0.09, -0.1, -0.12),
       individualCount = c("Marker 1", "Marker 2", "Marker 3")
     )

    output$leafletMap <- renderLeaflet({
      leaflet(data = data) %>%
        addTiles() %>%
        addMarkers(
          ~longitudeDecimal, ~latitudeDecimal,
          icon = icon("location-dot"), popup = ~individualCount, label = ~individualCount,
          layerId = ~id
        )
    })

    ##### THIS WORKS ONLY WHEN THE DATA PROVIDED TO LEAFLET IS NOT REACTIVE I DON'T GET WHY ####
    observeEvent(input$leafletMap_marker_click, {
      # Get the information about the clicked marker
      click_info <- input$leafletMap_marker_click
      print(click_info)

      # Check if a marker was clicked
      if (!is.null(click_info)) {
        # Extract the id of the clicked marker
        clicked_id <- data$id[data$longitudeDecimal == click_info$lng & data$latitudeDecimal == click_info$lat]

        # Print the id to the console (you can use it as needed)
        print(clicked_id)
      }
    })
  })

While this one don't...

box::use(
  reactable,
  shiny[h3, moduleServer, NS, tagList, fluidRow, column,observe,req,icon,
        uiOutput,renderUI,img,observeEvent],
  leaflet[makeIcon,leafletOutput,renderLeaflet,addTiles,setView,addProviderTiles,addMarkers,leaflet],
  dplyr[`%>%`,filter],
)
#' @export
ui <- function(id) {
  ns <- NS(id)
  tagList(
    fluidRow(column(width = 12,
            leafletOutput(outputId = ns("leafletMap")),
            uiOutput(ns("imageOutput"))
    ))
  )
}

#' @export
server <- function(id, data, session) {
  moduleServer(id, function(input, output, session) {

    # data <- data.frame(
    #   id = c(1, 2, 3),
    #   latitudeDecimal = c(51.505, 51.51, 51.52),
    #   longitudeDecimal = c(-0.09, -0.1, -0.12),
    #   individualCount = c("Marker 1", "Marker 2", "Marker 3")
    # )

    output$leafletMap <- renderLeaflet({
      leaflet(data = data()) %>%
      #leaflet(data = data) %>%
        addTiles() %>%
        addMarkers(
          ~longitudeDecimal, ~latitudeDecimal,
          icon = icon("location-dot"), popup = ~individualCount, label = ~individualCount,
          layerId = ~id
        )
    })

    ##### THIS WORKS ONLY WHEN THE DATA PROVIDED TO LEAFLET IS NOT REACTIVE I DON'T GET WHY ####
    observeEvent(input$leafletMap_marker_click, {
      # Get the information about the clicked marker
      click_info <- input$leafletMap_marker_click
      print(click_info)

      # Check if a marker was clicked
      if (!is.null(click_info)) {
        # Extract the id of the clicked marker
        clicked_id <- data$id[data$longitudeDecimal == click_info$lng & data$latitudeDecimal == click_info$lat]

        # Print the id to the console (you can use it as needed)
        print(clicked_id)
      }
    })
  })

So I skip displayed picture from clickable markers for now... ๐Ÿ˜ž

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.