gamcoh / st-card

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

Feature - Option to call a function when clicked. #3

Closed hortojac closed 1 year ago

hortojac commented 1 year ago

I think having the ability to call a function when clicked would be a great feature. This would allow you to use the streamlit-extras switch page component for example when used in a function. Could add this feature as optional and if the URL argument is None then it would resort to the function call if present.

gamcoh commented 1 year ago

That would be great! Are you currently working on that? I see you forked the repo

hortojac commented 1 year ago

Yes, I forked the repo and I am currently working on implementing it, unless you would prefer too?

gamcoh commented 1 year ago

Oh no it's great I'm happy to let you do it, comment here if you want some help on anything

philippeboyd commented 1 year ago

@hortojac any news on that callback feature?

gamcoh commented 1 year ago

Hi @philippeboyd I'm taking over this feature request, how do you imagine this would work?

Would you have imagine something like that?

from streamlit_card import card

card(
  title="Hello World!",
  text="Some description",
  image="http://placekitten.com/200/300",
  func=lambda: st.session_state["x"] = "foo"
)

Isn't it better to do this:

from streamlit_card import card

hasClicked = card(
  title="Hello World!",
  text="Some description",
  image="http://placekitten.com/200/300",
)

if hasClicked:
  st.session_state["x"] = "foo"

which is already implemented

philippeboyd commented 1 year ago

Hi @gamcoh , personnaly I prefer the first option (but func being renamed to on_click) as it would go on par with Streamlit's button component.

from streamlit_card import card

card(
  title="Hello World!",
  text="Some description",
  image="http://placekitten.com/200/300",
  on_click=lambda: st.session_state["x"] = "foo",
)
gamcoh commented 1 year ago

done