callbacktaipy

Taipy callback function with parameters


in the following taipy code, the intended functionality is that when the image is clicked a paramter cat should be passed to select_category function, but i couldn't get it to work without error: --- 1 warning(s) were found for page 'TaiPy_partials_0' ---

<|{images_folder+r'\juice1.png'}|image|on_action=select_category(cat)|> def select_category(state,cat): print(cat)

what is the right why to pass parameters/argument to the function from once an image is clicked?


Solution

  • Don't pass cat as a property of your function. The proper syntax is:

    <|{images_folder+r'\juice1.png'}|image|on_action=select_category|>
    

    ` You should retrieve cat in your state if you first defined it somewhere in your script.

    cat = "your default value" 
    
    def select_category(state):
        print(state.cat)