XPMaster commited on
Commit
3b33677
·
1 Parent(s): 6a2658f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -25
app.py CHANGED
@@ -1,27 +1,58 @@
1
  import streamlit as 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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn import datasets
5
+ from sklearn.cluster import KMeans
6
+ import matplotlib.pyplot as plt
7
 
8
+ # JS hack to add a toggle button for the sidebar
9
+ st.markdown("""
10
+ <style>
11
+ .reportview-container .main .block-container {
12
+ max-width: 100%;
13
+ }
14
+ </style>
15
+ """, unsafe_allow_html=True)
16
+
17
+ # Load iris dataset
18
+ iris = datasets.load_iris()
19
+ X = iris.data
20
+
21
+ st.title('Understanding K-Means Clustering')
22
+
23
+ tab1, tab2 = st.tabs(["Basic ", "Advanced 🔬"])
24
+
25
+ if "toggle" not in st.session_state:
26
+ st.session_state.toggle = True
27
+
28
+ toggle_button = st.button("Toggle Sidebar")
29
+
30
+ if toggle_button:
31
+ st.session_state.toggle = not st.session_state.toggle
32
+
33
+ if st.session_state.toggle:
34
+
35
+ # User Input on Sidebar
36
+ st.sidebar.header('Input Your Flower Data')
37
+ def user_input_features():
38
+ sepal_length = st.sidebar.slider('Sepal Length (cm)', 4.0, 8.0, 6.5)
39
+ sepal_width = st.sidebar.slider('Sepal Width (cm)', 2.0, 4.5, 3.5)
40
+ petal_length = st.sidebar.slider('Petal Length (cm)', 1.0, 7.0, 4.5)
41
+ petal_width = st.sidebar.slider('Petal Width (cm)', 0.1, 2.5, 1.5)
42
+ return [sepal_length, sepal_width, petal_length, petal_width]
43
+
44
+ user_features = user_input_features()
45
+
46
+ # Rest of your code remains largely unchanged
47
+ # We just use the st.session_state.toggle to conditionally display certain elements
48
+
49
+ with tab1:
50
+ # ...
51
+ # Rest of your code for tab1
52
+ # ...
53
+ pass
54
+ with tab2:
55
+ # ...
56
+ # Rest of your code for tab2
57
+ # ...
58
+ pass