Home > Software design >  How to add next and previous buttons by using streamlit
How to add next and previous buttons by using streamlit

Time:11-28

I am viewing images and files side by side for that I need next and previous button because each time I don't want to click 1,2,3,4... instead of this if I gave next means it should open next image and file and if I give previous means it should open previous image and file

st.button("next",on_click=image,args=(imagepath,jsonpath,))

Here next giving me many next buttons instead of this I need only one to view all the images and I need to add previous button also I don't know how On_click=image here image means function where I am printing both image file and json file side by side and args args means I am sending imagepath and jsonpath now I need to add next and previous button to view the image and json file And one more thing now I am viewing both image and json file in one click so if I give next it should open both image and json

CodePudding user response:

Here is a sample photo viewer code. It reads image and json files in the image folder, save it to a list, and use this list in the app.

There is a session state variable called idx used to track the next and previous.

"""Images are taken from https://unsplash.com/
"""


import json
import os

import streamlit as st


st.set_page_config(
    page_title="Photo viewer",
    page_icon="           
  • Related