giswqs commited on
Commit
bd01bd5
1 Parent(s): b20db93

Init commit

Browse files
Files changed (7) hide show
  1. .gitignore +1 -0
  2. Procfile +1 -0
  3. app.py +15 -0
  4. apps/home.py +28 -0
  5. multiapp.py +63 -0
  6. requirements.txt +7 -0
  7. setup.sh +8 -0
.gitignore CHANGED
@@ -2,6 +2,7 @@
2
  __pycache__/
3
  *.py[cod]
4
  *$py.class
 
5
 
6
  # C extensions
7
  *.so
 
2
  __pycache__/
3
  *.py[cod]
4
  *$py.class
5
+ *.html
6
 
7
  # C extensions
8
  *.so
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: sh setup.sh && streamlit run app.py
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from multiapp import MultiApp
3
+ from apps import home
4
+
5
+ # st.set_page_config(layout="wide")
6
+
7
+
8
+ apps = MultiApp()
9
+
10
+ # Add all your application here
11
+
12
+ apps.add_app("Home", home.app)
13
+
14
+ # The main app
15
+ apps.run()
apps/home.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import leafmap.foliumap as leafmap
3
+
4
+
5
+ def app():
6
+ st.title("Home")
7
+
8
+ st.header("Introduction")
9
+ st.write(
10
+ "This web app demonstrates how to create interactive maps using streamlit and open-source mapping libraries."
11
+ )
12
+
13
+ st.markdown("Source code: <https://github.com/giswqs/streamlit-geospatial>")
14
+ st.markdown("Web app: <https://gishub.org/streamlit-geospatial>")
15
+
16
+ st.header("Example")
17
+
18
+ filepath = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_cities.csv"
19
+ m = leafmap.Map(tiles="stamentoner")
20
+ m.add_heatmap(
21
+ filepath,
22
+ latitude="latitude",
23
+ longitude="longitude",
24
+ value="pop_max",
25
+ name="Heat map",
26
+ radius=20,
27
+ )
28
+ m.to_streamlit(width=700, height=500)
multiapp.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Frameworks for running multiple Streamlit applications as a single app.
2
+ """
3
+ import streamlit as st
4
+
5
+ # app_state = st.experimental_get_query_params()
6
+ # app_state = {k: v[0] if isinstance(v, list) else v for k, v in app_state.items()} # fetch the first item in each query string as we don't have multiple values for each query string key in this example
7
+
8
+
9
+ class MultiApp:
10
+ """Framework for combining multiple streamlit applications.
11
+ Usage:
12
+ def foo():
13
+ st.title("Hello Foo")
14
+ def bar():
15
+ st.title("Hello Bar")
16
+ app = MultiApp()
17
+ app.add_app("Foo", foo)
18
+ app.add_app("Bar", bar)
19
+ app.run()
20
+ It is also possible keep each application in a separate file.
21
+ import foo
22
+ import bar
23
+ app = MultiApp()
24
+ app.add_app("Foo", foo.app)
25
+ app.add_app("Bar", bar.app)
26
+ app.run()
27
+ """
28
+
29
+ def __init__(self):
30
+ self.apps = []
31
+
32
+ def add_app(self, title, func):
33
+ """Adds a new application.
34
+ Parameters
35
+ ----------
36
+ func:
37
+ the python function to render this app.
38
+ title:
39
+ title of the app. Appears in the dropdown in the sidebar.
40
+ """
41
+ self.apps.append({"title": title, "function": func})
42
+
43
+ def run(self):
44
+ app_state = st.experimental_get_query_params()
45
+ app_state = {
46
+ k: v[0] if isinstance(v, list) else v for k, v in app_state.items()
47
+ } # fetch the first item in each query string as we don't have multiple values for each query string key in this example
48
+
49
+ # st.write('before', app_state)
50
+
51
+ titles = [a["title"] for a in self.apps]
52
+ functions = [a["function"] for a in self.apps]
53
+ default_radio = titles.index(app_state["page"]) if "page" in app_state else 0
54
+
55
+ st.sidebar.title("Navigation")
56
+
57
+ title = st.sidebar.radio("Go To", titles, index=default_radio, key="radio")
58
+
59
+ app_state["page"] = st.session_state.radio
60
+ # st.write('after', app_state)
61
+
62
+ st.experimental_set_query_params(**app_state)
63
+ functions[titles.index(title)]()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ geopandas
2
+ keplergl
3
+ streamlit
4
+ streamlit-folium
5
+ streamlit-keplergl
6
+ git+git://github.com/giswqs/leafmap
7
+ git+git://github.com/giswqs/geemap
setup.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ mkdir -p ~/.streamlit/
2
+ echo "\
3
+ [server]\n\
4
+ headless = true\n\
5
+ port = $PORT\n\
6
+ enableCORS = false\n\
7
+ \n\
8
+ " > ~/.streamlit/config.toml