Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,35 +2,26 @@ import streamlit as st
|
|
| 2 |
|
| 3 |
st.title('Togglable Sidebar Example')
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
st.session_state.hide_sidebar = True
|
| 8 |
-
|
| 9 |
-
hide_css = """
|
| 10 |
-
<style>
|
| 11 |
-
div[data-testid="stSidebar"][aria-expanded="true"] > div:first-child {
|
| 12 |
-
display: none !important;
|
| 13 |
-
}
|
| 14 |
-
</style>
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
show_css = """
|
| 18 |
<style>
|
| 19 |
-
|
| 20 |
-
display:
|
| 21 |
}
|
| 22 |
</style>
|
| 23 |
"""
|
| 24 |
|
| 25 |
-
if
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
st.markdown(show_css, unsafe_allow_html=True)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
st.session_state.hide_sidebar = not st.session_state.hide_sidebar
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
st.title('Togglable Sidebar Example')
|
| 4 |
|
| 5 |
+
# This is the CSS to hide the sidebar
|
| 6 |
+
css_code = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
<style>
|
| 8 |
+
[data-testid="stSidebar"] {
|
| 9 |
+
display: none;
|
| 10 |
}
|
| 11 |
</style>
|
| 12 |
"""
|
| 13 |
|
| 14 |
+
# Initialize the session state variable if it doesn't exist
|
| 15 |
+
if 'show_sidebar' not in st.session_state:
|
| 16 |
+
st.session_state.show_sidebar = False
|
|
|
|
| 17 |
|
| 18 |
+
if st.button("Toggle Sidebar"):
|
| 19 |
+
st.session_state.show_sidebar = not st.session_state.show_sidebar
|
|
|
|
| 20 |
|
| 21 |
+
# If we want to show the sidebar, we'll use Streamlit's standard sidebar functions.
|
| 22 |
+
# If we want to hide it, we'll inject the CSS code to hide the sidebar.
|
| 23 |
+
if st.session_state.show_sidebar:
|
| 24 |
+
st.sidebar.title("Sidebar")
|
| 25 |
+
st.sidebar.write("This is the sidebar content.")
|
| 26 |
+
else:
|
| 27 |
+
st.markdown(css_code, unsafe_allow_html=True)
|