Spaces:
Sleeping
Sleeping
test
Browse files
app.py
CHANGED
|
@@ -12,19 +12,10 @@
|
|
| 12 |
# limitations under the License.
|
| 13 |
|
| 14 |
"""An example of showing species richness from GBIF data."""
|
| 15 |
-
|
| 16 |
-
import os
|
| 17 |
-
|
| 18 |
-
# +
|
| 19 |
-
import altair as alt
|
| 20 |
-
import numpy as np
|
| 21 |
-
import pandas as pd
|
| 22 |
import pydeck as pdk
|
| 23 |
import streamlit as st
|
| 24 |
-
|
| 25 |
import ibis
|
| 26 |
from ibis import _
|
| 27 |
-
# -
|
| 28 |
|
| 29 |
# SETTING PAGE CONFIG TO WIDE MODE AND ADDING A TITLE AND FAVICON
|
| 30 |
st.set_page_config(layout="wide", page_title="GBIF Biodiversity Demo", page_icon=":butterfly:")
|
|
@@ -93,33 +84,10 @@ def map(data, lat, lon, zoom):
|
|
| 93 |
)
|
| 94 |
|
| 95 |
|
| 96 |
-
# CALCULATE MIDPOINT FOR GIVEN SET OF DATA
|
| 97 |
-
@st.cache_data
|
| 98 |
-
def mpoint(lat, lon):
|
| 99 |
-
return (np.average(lat), np.average(lon))
|
| 100 |
-
|
| 101 |
-
|
| 102 |
# LAYING OUT THE TOP SECTION OF THE APP
|
| 103 |
row1_1, row1_2 = st.columns((2, 3))
|
| 104 |
|
| 105 |
-
|
| 106 |
-
# THIS ALLOWS YOU TO PASS A STATEFUL URL TO SOMEONE WITH A SPECIFIC HOUR SELECTED,
|
| 107 |
-
# E.G. https://share.streamlit.io/streamlit/demo-uber-nyc-pickups/main?pickup_hour=2
|
| 108 |
-
if not st.session_state.get("url_synced", False):
|
| 109 |
-
try:
|
| 110 |
-
year = int(st.query_params["year"][0])
|
| 111 |
-
st.session_state["year"] = year
|
| 112 |
-
st.session_state["url_synced"] = True
|
| 113 |
-
except KeyError:
|
| 114 |
-
pass
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
# IF THE SLIDER CHANGES, UPDATE THE QUERY PARAM
|
| 118 |
-
def update_query_params():
|
| 119 |
-
year_selected = st.session_state["year"]
|
| 120 |
-
st.query_params["year"]=year_selected
|
| 121 |
-
|
| 122 |
-
|
| 123 |
with row1_1:
|
| 124 |
st.title("GBIF Species Richness")
|
| 125 |
taxa = st.text_input('taxonomic class (Chordates only)')
|
|
@@ -144,7 +112,7 @@ with row1_2:
|
|
| 144 |
# SETTING THE ZOOM LOCATIONS
|
| 145 |
midpoint = (52.0, -1.0) #mpoint(data["lat"], data["lon"])
|
| 146 |
# STREAMLIT APP LAYOUT
|
| 147 |
-
data =
|
| 148 |
|
| 149 |
# +
|
| 150 |
row2_1, row2_2, row2_3, row2_4 = st.columns((2, 1, 1, 1))
|
|
@@ -153,17 +121,17 @@ with row2_1:
|
|
| 153 |
st.write(
|
| 154 |
f"""**All**"""
|
| 155 |
)
|
| 156 |
-
map(
|
| 157 |
|
| 158 |
with row2_2:
|
| 159 |
st.write(f"Selected class is {taxa}")
|
| 160 |
-
map(load_class(taxa=
|
| 161 |
|
| 162 |
with row2_3:
|
| 163 |
st.write("**Mammals**")
|
| 164 |
-
map(load_class("Mammalia"), midpoint[0], midpoint[1], 5)
|
| 165 |
|
| 166 |
with row2_4:
|
| 167 |
st.write("**Birds**")
|
| 168 |
-
map(load_class("Aves"), midpoint[0], midpoint[1], 5)
|
| 169 |
|
|
|
|
| 12 |
# limitations under the License.
|
| 13 |
|
| 14 |
"""An example of showing species richness from GBIF data."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
import pydeck as pdk
|
| 16 |
import streamlit as st
|
|
|
|
| 17 |
import ibis
|
| 18 |
from ibis import _
|
|
|
|
| 19 |
|
| 20 |
# SETTING PAGE CONFIG TO WIDE MODE AND ADDING A TITLE AND FAVICON
|
| 21 |
st.set_page_config(layout="wide", page_title="GBIF Biodiversity Demo", page_icon=":butterfly:")
|
|
|
|
| 84 |
)
|
| 85 |
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
# LAYING OUT THE TOP SECTION OF THE APP
|
| 88 |
row1_1, row1_2 = st.columns((2, 3))
|
| 89 |
|
| 90 |
+
## Interactive elements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
with row1_1:
|
| 92 |
st.title("GBIF Species Richness")
|
| 93 |
taxa = st.text_input('taxonomic class (Chordates only)')
|
|
|
|
| 112 |
# SETTING THE ZOOM LOCATIONS
|
| 113 |
midpoint = (52.0, -1.0) #mpoint(data["lat"], data["lon"])
|
| 114 |
# STREAMLIT APP LAYOUT
|
| 115 |
+
data =
|
| 116 |
|
| 117 |
# +
|
| 118 |
row2_1, row2_2, row2_3, row2_4 = st.columns((2, 1, 1, 1))
|
|
|
|
| 121 |
st.write(
|
| 122 |
f"""**All**"""
|
| 123 |
)
|
| 124 |
+
map(load_data(zoom=zoom), midpoint[0], midpoint[1], 5)
|
| 125 |
|
| 126 |
with row2_2:
|
| 127 |
st.write(f"Selected class is {taxa}")
|
| 128 |
+
map(load_class(taxa=taxa, zoom=zoom), midpoint[0], midpoint[1], 5)
|
| 129 |
|
| 130 |
with row2_3:
|
| 131 |
st.write("**Mammals**")
|
| 132 |
+
map(load_class("Mammalia", zoom=zoom), midpoint[0], midpoint[1], 5)
|
| 133 |
|
| 134 |
with row2_4:
|
| 135 |
st.write("**Birds**")
|
| 136 |
+
map(load_class("Aves", zoom=zoom), midpoint[0], midpoint[1], 5)
|
| 137 |
|