IMERSS / inat-components

A suite of React components for rendering iNaturalist data.
https://imerss.github.io/inat-components/
MIT License
6 stars 1 forks source link
citizen-science inat inaturalist nature react

inat-components

This repo contains some pre-built React components to display iNaturalist data on your own sites. The original goal was to provide add an interactive page to the BC Lepidoptera website so visitors could see some high-level information about lepidoptera (butterflies and moths) spotted in British Columbia. But the code was written to allow it to be re-used by any website and for any taxon or place.

This repo stores both the components themselves (published to npm under @imerss/inat-components) and the backend scripts to scrape iNat data and store it in JSON files for use by the front-end components (@imerss/inat-components-utils). See below for an explanation of why that's necessary.

You have a choice with the front-end components to display any of four pieces of information:

The main TaxonPanel component displays the information in tabbed format. Everything from text, labels and styles can be customized, including which tabs appear.

Demo

How it works

diagram

  1. iNaturalist stores all the of the data about observations, taxonomy, observers and so on. They kindly provide a public API (Application Programming Interface) to allow developers to request data programmatically. The inat-components repo relies on that API to request the data that you need.
  2. In between the iNat API and your own website is a script (@imerss/inat-components-utils) that does the job of calling iNat and storing the data you want into separate data files. This code can run wherever you want - your own website is probably the most convenient. But wherever it is, it has to put the data files in a place that can be called by a website (i.e. an http/https location).
  3. The front-end code running on your website then makes requests to the data files. They are designed to be as small as possible and contain the minimal amount of data needed. This ensures the requests are as quick as possible so the user viewing your site doesn't have to wait.

Why the need for #2? Why not just call the iNat API from your own website? A few reasons:

Installation

To use the components in your React code, just use npm, pnpm or yarn - whatever package manager you want.

npm install @imerss/inat-components
pnpm install @imerss/inat-components
yarn add @imerss/inat-components

Features:

Available components

We'll go into details about each of these components below, but here's what's available.

<TaxonPanel />

This is a pre-built panel containing all visualization data available, grouped into tabs: recent observations, common taxa, favourites and a summary tab. You get less control using this component than all the others below, but it means you don't have to write any code.

<RecentObservations />

This component shows a grid of recent observations made within a particular taxon. Since the purpose of this is to show recent sightings, you'll want the data source refreshed fairly frequently, e.g. every 10 or 15 minutes.

<CommonTaxa />

This component shows a grid of the most common taxa within a particular taxon, place and time period, e.g. the most common beetles spotted in Canada in the current year.

<Favourites />

This component shows a grid of the most common taxa within a particular taxon, place and time period, e.g. the most common beetles spotted in Canada in the current year.

<Summary />

This shows a high-level summary of the selected taxon and place. It shows information such as total number of observations, total number of observers, a histogram of data observations per month, top observers, total number of species and observation/species counts of the next taxonomical sub-level, e.g. if you specified an Order as the primary taxon ID, it would provide family-level stats (Kingdom -> Phylum -> Class -> Order -> Family -> Genus -> Species).

Local dev env

Demo code

Let's start with running your local dev environment. To run the demo application, do this:

That'll open up a browser in dev mode where you can play around with the code and see how it works. It's loading the content of apps/demo.

Please note that due to an issue with Rollup, shared code between the inat-components and inat-components-utils packages (found in the /packages folder) is actually stored in the root shared/ folder. That is copied into 2 separate src/__shared/ folders within each package during dev mode, so don't edit the code there! Always edit the code in the root shared/ folder or your changes will be lost. Does this suck? Yes it does.

Standalone version

A second way to run things locally is with the standalone version. This is actually just a simple, single HTML page that links to a standalone version of the script (a single JS file, pre-bundled with everything you need). You can then use simple JS + CSS to pass in whatever values you need to configure the application. For more information see the package documentation.

Changelog

@imerss/inat-components

@imerss/inat-components-utils