gamcoh / st-card

Streamlit component for UI cards
https://pypi.org/project/streamlit-card/
MIT License
116 stars 19 forks source link

Click on multiple cards #17

Closed Haaaaaaaaaland closed 11 months ago

Haaaaaaaaaland commented 1 year ago

Hello,

Thank you for providing the card feature!

When using multiple cards, how can I get click results for each card? For instance, with the following code:

hasClicked1 = card(
    title="111",
    text="Some description",
    image="http://placekitten.com/200/300",
    key="111",
    on_click=lambda: print("111"),
)
hasClicked2 = card(
    title="222",
    text="Some description",
    image="http://placekitten.com/200/300",
    key="222",
    on_click=lambda: print("222"),
)
print(f"{hasClicked1} {hasClicked2}")

When 111 is clicked, the result is:

True False  # print

And click 222, the result is:

True True  # print ...?

Since I only clicked on the "222" card, I hoped that "False True" would come out, but it didn't work as expected.

How can i fix it?

Thank you in advance for your response!

OJddJO commented 1 year ago

Try using experimental_rerun()

if hasClicked1 or hasClicked2:
    st.experimental_rerun()

Something like that, since the state of cards are persistent.

gamcoh commented 1 year ago

@Haaaaaaaaaland is your issue solved?