Next and Previous Buttons

Hi,
I have a problem with navigation buttons. When I try to move to the next command
After clicking next button inside if statement , It keeps showing me the previous part.
And only after clicking again on the next button it does not show the previous part.
The goal is to move between texts and display only that text for each link

if st.session_state.papers:
               if st.session_state.count < len(st.session_state.papers):
                 st.write("Progress: ", st.session_state.count + 1 , "/", len(st.session_state.papers))
                 text = st.session_state.papers[st.session_state.count]["Description"]
                 link = st.session_state.papers[st.session_state.count]["Link"]
                 st.write(text)
                 st.write(link)
                 label = st.selectbox("Do you want to include this resource to your content?:", [None,"Yes","No"], index=None)
                 if st.button("Next ⏭️"):
                     if st.session_state.count + 1 > len(st.session_state.papers):
                        st.session_state.count = 0
                     else:
                         st.session_state.count += 1             
                     st.session_state.label_list.append(label)
                     if label == "Yes":
                         st.session_state.final_text.append(text)
                         st.session_state.final_link.append(link)              
               if st.session_state.count > 0: 
                 if st.button("⏮️ Previous"):
                     st.session_state.label_list.pop()
                     if st.session_state.label_list[-1] == "Yes":
                        st.session_state.final_text.pop()  
                        st.session_state.final_link.pop()
                     st.session_state.count -= 1

Welcome to the Streamlit community, @ceybe! It’s great to have you here! :hugs:

I’ve created an app that addresses navigation issues like the ones you’re encountering.

Export-1698673416494

Here’s code that you can use:

Hopefully, it might provide a solution for your app’s navigation needs. If not, let me know and we can investigate your issue further.

Best wishes,
Charly

1 Like

Thank you for your help. I have one more question. Is it possible to add a “Yes or No” selectbox to it and select quotes with navigation buttons. After all the selections. Write only “Yes” ones together.

You’re welcome! :hugs:

I have one more question. Is it possible to add a “Yes or No” selectbox to it and select quotes with navigation buttons. After all the selections. Write only “Yes” ones together.

Also, what do you mean, exactly? Could you please elaborate?

Thanks,
Charly

I want to make a selection among the given quotes. The user will navigate between the quotes with the navigation buttons and select “Yes” because they chose them through the select box, or “No” because they do not want them to remain. I want to record the answers of the users and when they submit their answers at the end, I want to print the quotes they choose one under the other. Think like it is a catalogue, by selecting the ones you like with the selectbox and viewing them with the next and previous buttons among the quotes.

You can use Trubrics’ Feedback component, and then connect your app to a database to keep track of the responses.

Here’s a helpful resource for connecting your Streamlit apps to databases.

I hope this helps! :slight_smile:

Charly

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.