castledan commited on
Commit
19b905a
Β·
1 Parent(s): c5cc81a

hide menu button if on streamlit

Browse files
app/Home.py CHANGED
@@ -1,11 +1,14 @@
1
  """Home page for Streamlit app."""
2
  import streamlit as st
3
  from src.config_parameters import config
4
- from src.utils_sidebar import add_about, add_logo
5
 
6
  # Page configuration
7
  st.set_page_config(layout="wide")
8
 
 
 
 
9
  # Create sidebar
10
  add_logo("app/img/MA-logo.png")
11
  add_about()
 
1
  """Home page for Streamlit app."""
2
  import streamlit as st
3
  from src.config_parameters import config
4
+ from src.utils_layout import add_about, add_logo, toggle_menu_button
5
 
6
  # Page configuration
7
  st.set_page_config(layout="wide")
8
 
9
+ # If app is deployed hide menu button
10
+ toggle_menu_button()
11
+
12
  # Create sidebar
13
  add_logo("app/img/MA-logo.png")
14
  add_about()
app/pages/1_🌍_Flood_extent_analysis.py CHANGED
@@ -11,12 +11,15 @@ from folium.plugins import Draw, Geocoder, MiniMap
11
  from src.config_parameters import config
12
  from src.utils_ee import ee_initialize
13
  from src.utils_flood_analysis import derive_flood_extents
14
- from src.utils_sidebar import add_about, add_logo
15
  from streamlit_folium import st_folium
16
 
17
  # Page configuration
18
  st.set_page_config(layout="wide")
19
 
 
 
 
20
  # Create sidebar
21
  add_logo("app/img/MA-logo.png")
22
  add_about()
 
11
  from src.config_parameters import config
12
  from src.utils_ee import ee_initialize
13
  from src.utils_flood_analysis import derive_flood_extents
14
+ from src.utils_layout import add_about, add_logo, toggle_menu_button
15
  from streamlit_folium import st_folium
16
 
17
  # Page configuration
18
  st.set_page_config(layout="wide")
19
 
20
+ # If app is deployed hide menu button
21
+ toggle_menu_button()
22
+
23
  # Create sidebar
24
  add_logo("app/img/MA-logo.png")
25
  add_about()
app/pages/2_πŸ“–_Documentation.py CHANGED
@@ -2,11 +2,14 @@
2
  import streamlit as st
3
  from PIL import Image
4
  from src.config_parameters import config
5
- from src.utils_sidebar import add_about, add_logo
6
 
7
  # Page configuration
8
  st.set_page_config(layout="wide")
9
 
 
 
 
10
  # Create sidebar
11
  add_logo("app/img/MA-logo.png")
12
  add_about()
 
2
  import streamlit as st
3
  from PIL import Image
4
  from src.config_parameters import config
5
+ from src.utils_layout import add_about, add_logo, toggle_menu_button
6
 
7
  # Page configuration
8
  st.set_page_config(layout="wide")
9
 
10
+ # If app is deployed hide menu button
11
+ toggle_menu_button()
12
+
13
  # Create sidebar
14
  add_logo("app/img/MA-logo.png")
15
  add_about()
app/src/utils_ee.py CHANGED
@@ -1,16 +1,15 @@
1
  """Module for ee-related functionalities."""
2
- import os
3
-
4
  import ee
5
  import streamlit as st
6
  from ee import oauth
7
  from google.oauth2 import service_account
 
8
 
9
 
10
  @st.experimental_memo
11
  def ee_initialize():
12
  """Initialise Google Earth Engine."""
13
- if "HOSTNAME" in os.environ and os.environ["HOSTNAME"] == "streamlit":
14
  service_account_keys = st.secrets["ee_keys"]
15
  credentials = service_account.Credentials.from_service_account_info(
16
  service_account_keys, scopes=oauth.SCOPES
 
1
  """Module for ee-related functionalities."""
 
 
2
  import ee
3
  import streamlit as st
4
  from ee import oauth
5
  from google.oauth2 import service_account
6
+ from src.utils_layout import is_app_on_streamlit
7
 
8
 
9
  @st.experimental_memo
10
  def ee_initialize():
11
  """Initialise Google Earth Engine."""
12
+ if is_app_on_streamlit():
13
  service_account_keys = st.secrets["ee_keys"]
14
  credentials = service_account.Credentials.from_service_account_info(
15
  service_account_keys, scopes=oauth.SCOPES
app/src/{utils_sidebar.py β†’ utils_layout.py} RENAMED
@@ -1,10 +1,34 @@
1
  """Functions for the sidebar of the Streamlit app."""
2
  import base64
 
3
  from datetime import date
4
 
5
  import streamlit as st
6
  from src.config_parameters import config
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  sidebar_title = "Flood Mapping Tool"
9
 
10
 
 
1
  """Functions for the sidebar of the Streamlit app."""
2
  import base64
3
+ import os
4
  from datetime import date
5
 
6
  import streamlit as st
7
  from src.config_parameters import config
8
 
9
+
10
+ # Check if app is deployed
11
+ def is_app_on_streamlit():
12
+ """Check whether the app is on streamlit or runs locally."""
13
+ return "HOSTNAME" in os.environ and os.environ["HOSTNAME"] == "streamlit"
14
+
15
+
16
+ # General layout
17
+ def toggle_menu_button():
18
+ """If app is on streamlit, hide menu button."""
19
+ if is_app_on_streamlit():
20
+ st.markdown(
21
+ """
22
+ <style>
23
+ #MainMenu {visibility: hidden;}
24
+ footer {visibility: hidden;}
25
+ </style>
26
+ """,
27
+ unsafe_allow_html=True,
28
+ )
29
+
30
+
31
+ # Sidebar
32
  sidebar_title = "Flood Mapping Tool"
33
 
34