okld/streamlit-elements

Callbacks with args

ChrisDelClea opened this issue · 2 comments

Hey @okld ,

can i somehow pass args to a callback function?

def handle_onclick(event, args):
      passed_arg = args[0]

mui.button("clickme", onClick=handle_onclick, args=("blub"))

Why args at all? I want to pass some information to the button as i have a button-list.
So i need somehow to save some information, what button was clicked.

Hey @okld ,

can i somehow pass args to a callback function?

def handle_onclick(event, args):
      passed_arg = args[0]

mui.button("clickme", onClick=handle_onclick, args=("blub"))

Why args at all? I want to pass some information to the button as i have a button-list. So i need somehow to save some information, what button was clicked.

You can do this

import streamlit as st
from functools import partial

def handle_onclick(args, event):
      passed_arg = args

mui.button("clickme", onClick=partial(handle_onclick, "blub"))

thanks, @lkdd-ao .