Summary
Button not working
Steps to reproduce
Code snippet:
import streamlit as st
#Session states variables
#Tracks current page number
if 'current_page_number' not in st.session_state:
st.session_state.current_page_number = 0
#Inits placeholder container to add / delete as required
if 'current_page_container' not in st.session_state:
st.session_state.current_page_container = st.empty()
#Bool to manage first render
if 'first_boot' not in st.session_state:
st.session_state.first_boot = False
#Next page
def step_up():
st.session_state.current_page_number = st.session_state.current_page_number + 1
render_page(st.session_state.current_page_number)
#Back page
def step_down():
if not st.session_state.current_page_number <= 0:
st.session_state.current_page_number = st.session_state.current_page_number - 1
render_page(st.session_state.current_page_number)
#Based on page number render
def render_page(page_number):
#Idk why but without rendering something first, it wont work
st.write(' ')
with st.session_state.current_page_container.container():
if page_number == 0:
st.write(f'This is connect page')
a = st.button('Connect')
if a:
st.write('pressed a')
if page_number == 1:
st.write(f'This is data class levels')
b = st.button(str(page_number))
#Load connect page (page_number = 0) upon first boot
if not st.session_state.first_boot:
render_page(st.session_state.current_page_number)
st.session_state.first_boot = True
#Navigation buttons
col1, mid, col2 = st.columns([1,3,1])
with col1:
back = st.button('Back', on_click = step_down, use_container_width = True, type = 'primary')
with col2:
next = st.button('Next', on_click = step_up, use_container_width = True, type = 'primary')
Expected behavior:
Press connect button a st.write() “pressed a”
Debug info
- Streamlit version: 1.18
- Python version: 3.8
Additional information
Whenever i press the “a” button labeled as “connect” nothing gets written in the screen. It just displays as blank and only shows the next and back buttons.