okld / streamlit-elements

Create a draggable and resizable dashboard in Streamlit, featuring Material UI widgets, Monaco editor (Visual Studio Code), Nivo charts, and more!
MIT License
679 stars 77 forks source link

Callbacks with args #23

Closed ChrisDelClea closed 1 year ago

ChrisDelClea commented 1 year ago

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.

lkdd-ao commented 1 year ago

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"))
ChrisDelClea commented 1 year ago

thanks, @lkdd-ao .