XPMaster commited on
Commit
640cbf4
β€’
1 Parent(s): 6e3dbb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -34
app.py CHANGED
@@ -121,38 +121,95 @@
121
  # excel_data = to_excel(df_to_export)
122
  # st.download_button(label='πŸ“₯ Download Excel', data=excel_data, file_name=f'{city}_forecast.xlsx', mime='application/vnd.ms-excel')
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  import streamlit as st
125
- import numpy as np
126
- import matplotlib.pyplot as plt
127
-
128
- # Sample data for multiple plots
129
- data = [(np.linspace(0, 10, 10), np.sin(np.linspace(0, 10, 10))) for _ in range(3)]
130
-
131
- # Initialize session state
132
- if 'current_plot_index' not in st.session_state:
133
- st.session_state['current_plot_index'] = 0
134
-
135
- def update_plot(index, x, y):
136
- plt.figure()
137
- plt.plot(x, y, marker='o')
138
- plt.title(f"Plot {index+1}")
139
- st.pyplot(plt)
140
-
141
- def next_plot():
142
- st.session_state['current_plot_index'] = (st.session_state['current_plot_index'] + 1) % len(data)
143
-
144
- # Display the plot
145
- index = st.session_state['current_plot_index']
146
- x, y = data[index]
147
- update_plot(index, x, y)
148
-
149
- # Select and update point
150
- point_index = st.number_input('Point Index', min_value=0, max_value=len(x)-1, step=1)
151
- new_value = st.number_input('New Y Value', value=y[point_index])
152
- if st.button('Update Point'):
153
- y[point_index] = new_value
154
- update_plot(index, x, y)
155
-
156
- # Next plot button
157
- if st.button('Next Plot'):
158
- next_plot()
 
121
  # excel_data = to_excel(df_to_export)
122
  # st.download_button(label='πŸ“₯ Download Excel', data=excel_data, file_name=f'{city}_forecast.xlsx', mime='application/vnd.ms-excel')
123
 
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+ # import streamlit as st
144
+ # import numpy as np
145
+ # import matplotlib.pyplot as plt
146
+
147
+ # # Sample data for multiple plots
148
+ # data = [(np.linspace(0, 10, 10), np.sin(np.linspace(0, 10, 10))) for _ in range(3)]
149
+
150
+ # # Initialize session state
151
+ # if 'current_plot_index' not in st.session_state:
152
+ # st.session_state['current_plot_index'] = 0
153
+
154
+ # def update_plot(index, x, y):
155
+ # plt.figure()
156
+ # plt.plot(x, y, marker='o')
157
+ # plt.title(f"Plot {index+1}")
158
+ # st.pyplot(plt)
159
+
160
+ # def next_plot():
161
+ # st.session_state['current_plot_index'] = (st.session_state['current_plot_index'] + 1) % len(data)
162
+
163
+ # # Display the plot
164
+ # index = st.session_state['current_plot_index']
165
+ # x, y = data[index]
166
+ # update_plot(index, x, y)
167
+
168
+ # # Select and update point
169
+ # point_index = st.number_input('Point Index', min_value=0, max_value=len(x)-1, step=1)
170
+ # new_value = st.number_input('New Y Value', value=y[point_index])
171
+ # if st.button('Update Point'):
172
+ # y[point_index] = new_value
173
+ # update_plot(index, x, y)
174
+
175
+ # # Next plot button
176
+ # if st.button('Next Plot'):
177
+ # next_plot()
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+ import plotly.express as px
194
  import streamlit as st
195
+ from streamlit_plotly_events import plotly_events
196
+
197
+ # Sample data
198
+ df = px.data.gapminder().query("country=='Canada'")
199
+ fig = px.line(df, x="year", y="lifeExp", title='Life Expectancy in Canada Over Years')
200
+
201
+ # Capture the selected points
202
+ selected_points = plotly_events(fig, click_event=True)
203
+
204
+ # Handle the click event
205
+ if selected_points:
206
+ st.write("You clicked on:", selected_points)
207
+ point_index = selected_points[0]['pointIndex']
208
+ new_value = st.number_input('Enter new value for life expectancy', value=df.iloc[point_index]['lifeExp'])
209
+ if st.button('Update Data'):
210
+ df.at[point_index, 'lifeExp'] = new_value
211
+ fig = px.line(df, x="year", y="lifeExp", title='Life Expectancy in Canada Over Years')
212
+ st.plotly_chart(fig)
213
+ else:
214
+ st.plotly_chart(fig)
215
+