generated from giswqs/streamlit-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6ce9dd0
Showing
14 changed files
with
443 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
private/ | ||
.vscode/ | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Qiusheng Wu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: sh setup.sh && streamlit run streamlit_app.py |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# streamlit-template | ||
|
||
A streamlit app template for geospatial applications based on [streamlit-option-menu](https://github.com/victoryhb/streamlit-option-menu). | ||
|
||
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/giswqs/streamlit-template/master?urlpath=proxy/8501/) | ||
|
||
App URL: <https://share.streamlit.io/giswqs/streamlit-template> | ||
|
||
![](https://i.imgur.com/xd64mCi.png) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import streamlit as st | ||
import leafmap.foliumap as leafmap | ||
|
||
|
||
def app(): | ||
|
||
st.title("Heatmap") | ||
|
||
filepath = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_cities.csv" | ||
m = leafmap.Map(tiles="stamentoner") | ||
m.add_heatmap( | ||
filepath, | ||
latitude="latitude", | ||
longitude="longitude", | ||
value="pop_max", | ||
name="Heat map", | ||
radius=20, | ||
) | ||
m.to_streamlit(height=700) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import streamlit as st | ||
import leafmap.foliumap as leafmap | ||
|
||
|
||
def app(): | ||
st.title("Home") | ||
|
||
st.markdown( | ||
""" | ||
A [streamlit](https://streamlit.io) app template for geospatial applications based on [streamlit-option-menu](https://github.com/victoryhb/streamlit-option-menu). | ||
To create a direct link to a pre-selected menu, add `?page=<app name>` to the URL, e.g., `?page=upload`. | ||
https://share.streamlit.io/giswqs/streamlit-template?page=upload | ||
""" | ||
) | ||
|
||
m = leafmap.Map(locate_control=True) | ||
m.add_basemap("ROADMAP") | ||
m.to_streamlit(height=700) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import os | ||
import geopandas as gpd | ||
import streamlit as st | ||
|
||
|
||
def save_uploaded_file(file_content, file_name): | ||
""" | ||
Save the uploaded file to a temporary directory | ||
""" | ||
import tempfile | ||
import os | ||
import uuid | ||
|
||
_, file_extension = os.path.splitext(file_name) | ||
file_id = str(uuid.uuid4()) | ||
file_path = os.path.join(tempfile.gettempdir(), f"{file_id}{file_extension}") | ||
|
||
with open(file_path, "wb") as file: | ||
file.write(file_content.getbuffer()) | ||
|
||
return file_path | ||
|
||
|
||
def app(): | ||
|
||
st.title("Upload Vector Data") | ||
|
||
row1_col1, row1_col2 = st.columns([2, 1]) | ||
width = 950 | ||
height = 600 | ||
|
||
with row1_col2: | ||
|
||
backend = st.selectbox( | ||
"Select a plotting backend", ["folium", "kepler.gl", "pydeck"], index=2 | ||
) | ||
|
||
if backend == "folium": | ||
import leafmap.foliumap as leafmap | ||
elif backend == "kepler.gl": | ||
import leafmap.kepler as leafmap | ||
elif backend == "pydeck": | ||
import leafmap.deck as leafmap | ||
|
||
url = st.text_input( | ||
"Enter a URL to a vector dataset", | ||
"https://github.com/giswqs/streamlit-geospatial/raw/master/data/us_states.geojson", | ||
) | ||
|
||
data = st.file_uploader( | ||
"Upload a vector dataset", type=["geojson", "kml", "zip", "tab"] | ||
) | ||
|
||
container = st.container() | ||
|
||
if data or url: | ||
if data: | ||
file_path = save_uploaded_file(data, data.name) | ||
layer_name = os.path.splitext(data.name)[0] | ||
elif url: | ||
file_path = url | ||
layer_name = url.split("/")[-1].split(".")[0] | ||
|
||
with row1_col1: | ||
if file_path.lower().endswith(".kml"): | ||
gpd.io.file.fiona.drvsupport.supported_drivers["KML"] = "rw" | ||
gdf = gpd.read_file(file_path, driver="KML") | ||
else: | ||
gdf = gpd.read_file(file_path) | ||
lon, lat = leafmap.gdf_centroid(gdf) | ||
if backend == "pydeck": | ||
|
||
column_names = gdf.columns.values.tolist() | ||
random_column = None | ||
with container: | ||
random_color = st.checkbox("Apply random colors", True) | ||
if random_color: | ||
random_column = st.selectbox( | ||
"Select a column to apply random colors", column_names | ||
) | ||
|
||
m = leafmap.Map(center=(40, -100)) | ||
# m = leafmap.Map(center=(lat, lon)) | ||
m.add_gdf(gdf, random_color_column=random_column) | ||
st.pydeck_chart(m) | ||
|
||
else: | ||
m = leafmap.Map(center=(lat, lon), draw_export=True) | ||
m.add_gdf(gdf, layer_name=layer_name) | ||
if backend == "folium": | ||
m.zoom_to_gdf(gdf) | ||
m.to_streamlit(width=width, height=height) | ||
|
||
else: | ||
with row1_col1: | ||
m = leafmap.Map() | ||
st.pydeck_chart(m) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Streamlit Web App</title> | ||
<style type="text/css"> | ||
html { | ||
overflow: auto; | ||
} | ||
html, | ||
body, | ||
div, | ||
iframe { | ||
margin: 0px; | ||
padding: 0px; | ||
height: 100%; | ||
border: none; | ||
} | ||
iframe { | ||
display: block; | ||
width: 100%; | ||
border: none; | ||
overflow-y: auto; | ||
overflow-x: hidden; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<iframe | ||
src="https://share.streamlit.io/giswqs/streamlit-template" | ||
frameborder="0" | ||
marginheight="0" | ||
marginwidth="0" | ||
width="100%" | ||
height="100%" | ||
scrolling="auto" | ||
allow="geolocation" | ||
> | ||
</iframe> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ffmpeg | ||
gifsicle | ||
build-essential | ||
python3-dev | ||
gdal-bin | ||
libgdal-dev |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# enable nbserverproxy | ||
jupyter serverextension enable --sys-prefix nbserverproxy | ||
# streamlit launches at startup | ||
mv streamlit_call.py ${NB_PYTHON_PREFIX}/lib/python*/site-packages/ | ||
# enable streamlit extension | ||
jupyter serverextension enable --sys-prefix streamlit_call |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--find-links=https://girder.github.io/large_image_wheels GDAL | ||
geemap | ||
geopandas | ||
jupyter-server-proxy | ||
keplergl | ||
leafmap | ||
localtileserver | ||
nbserverproxy | ||
streamlit | ||
streamlit-option-menu | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update | ||
# sudo apt-get update | ||
# sudo apt-get install python3-dev | ||
# sudo apt-get install gdal-bin | ||
# sudo apt-get install libgdal-dev | ||
# export CPLUS_INCLUDE_PATH=/usr/include/gdal | ||
# export C_INCLUDE_PATH=/usr/include/gdal | ||
# gdal-config --version | ||
# pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}') localtileserver | ||
|
||
mkdir -p ~/.streamlit/ | ||
echo "\ | ||
[server]\n\ | ||
headless = true\n\ | ||
port = $PORT\n\ | ||
enableCORS = false\n\ | ||
\n\ | ||
" > ~/.streamlit/config.toml |
Oops, something went wrong.