Been using Streamlit for a few days now and created a page hosted locally.
I am struggling with figuring out and understanding session states.
This is an basic example of my app with where the problem is happening.
import streamlit as st
from streamlit_card import card
import base64
with open('transparent.png', "rb") as f:
data = f.read()
encoded = base64.b64encode(data)
data = "data:image/png;base64," + encoded.decode("utf-8")
hasClicked = card(
title="Button 1",
text="Some description",
image=data,
on_click=lambda: print('hi'),
key='first'
)
hasClicked2 = card(
title="Button 2",
text="Some description",
image=data,
on_click=lambda: print('hi again'),
key='second'
)
When clicking on the card with key ‘first’ it prints ‘hi’. Which is what I intend. Afterwards though if I click on the card with key ‘second’ it will run as if I clicked the first and second card printing ‘hi’ \n ‘hi again’. When I would like it to just print ‘hi again’ if I select the second card.
It seems once either card is pressed then whenever another card is pressed all cards that previously were pressed get ran again.
Is there a way to reset or delete the state of the cards after they are pressed and perform their action?