Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,24 +15,30 @@ fig_bar = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
|
|
| 15 |
# Create another figure for a line chart
|
| 16 |
fig_line = px.line(df, x="Fruit", y="Amount", color="City")
|
| 17 |
|
| 18 |
-
#
|
| 19 |
if 'current_step' not in st.session_state:
|
| 20 |
st.session_state['current_step'] = 1
|
| 21 |
|
| 22 |
# Define navigation functions
|
| 23 |
-
def
|
| 24 |
-
st.session_state['current_step'] =
|
| 25 |
-
|
| 26 |
-
def go_to_step_2():
|
| 27 |
-
st.session_state['current_step'] = 2
|
| 28 |
|
| 29 |
# Layout
|
| 30 |
st.title('Interactive Dashboard with Steps')
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
if st.session_state['current_step'] == 1:
|
| 34 |
st.plotly_chart(fig_bar)
|
| 35 |
-
st.button('Next Step', on_click=go_to_step_2)
|
| 36 |
elif st.session_state['current_step'] == 2:
|
| 37 |
-
st.plotly_chart(fig_line)
|
| 38 |
-
st.button('Previous Step', on_click=go_to_step_1)
|
|
|
|
| 15 |
# Create another figure for a line chart
|
| 16 |
fig_line = px.line(df, x="Fruit", y="Amount", color="City")
|
| 17 |
|
| 18 |
+
# Session state for navigation
|
| 19 |
if 'current_step' not in st.session_state:
|
| 20 |
st.session_state['current_step'] = 1
|
| 21 |
|
| 22 |
# Define navigation functions
|
| 23 |
+
def go_to_step(step):
|
| 24 |
+
st.session_state['current_step'] = step
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Layout
|
| 27 |
st.title('Interactive Dashboard with Steps')
|
| 28 |
|
| 29 |
+
col1, col2 = st.columns(2)
|
| 30 |
+
with col1:
|
| 31 |
+
# "Previous" button will be disabled on the first step
|
| 32 |
+
prev_disabled = st.session_state['current_step'] == 1
|
| 33 |
+
st.button('Previous Step', on_click=lambda: go_to_step(st.session_state['current_step'] - 1), disabled=prev_disabled)
|
| 34 |
+
|
| 35 |
+
with col2:
|
| 36 |
+
# "Next" button will be disabled on the last step
|
| 37 |
+
next_disabled = st.session_state['current_step'] == 2
|
| 38 |
+
st.button('Next Step', on_click=lambda: go_to_step(st.session_state['current_step'] + 1), disabled=next_disabled)
|
| 39 |
+
|
| 40 |
+
# Display the appropriate chart based on the current step
|
| 41 |
if st.session_state['current_step'] == 1:
|
| 42 |
st.plotly_chart(fig_bar)
|
|
|
|
| 43 |
elif st.session_state['current_step'] == 2:
|
| 44 |
+
st.plotly_chart(fig_line)
|
|
|