Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
10.94k stars 775 forks source link

[🐛 BUG] Lambda function not working in delta property of metric #1518

Closed FlorianJacta closed 1 month ago

FlorianJacta commented 1 month ago

What went wrong? 🤔

Having a lambda function inside the delta property does not work. It would be really useful for it to work. Maybe, other properties are impacted.

image

WARNING:root:
--- 1 warning(s) were found for page '/'  ---
 - Warning 1: Metric: delta cannot be transformed into a number:
could not convert string to float: '<lambda>'
----------------------------------------------

Expected Behavior

It should work; the delta property should be able to use the lambda function to get the proper delta displayed on the metric. Maybe, other properties are impacted.

Steps to Reproduce Issue

# Import necessary libraries
import pandas as pd
import taipy as tp

import datetime as dt
import taipy.gui.builder as tgb

value = 10
previous_value = 5

with tgb.Page() as page:
    # Don't work
    tgb.metric(lambda value: value if value else 0,
        delta=lambda value, previous_value: (value - previous_value) 
                                                if value and previous_value else 0,
        max=20,
        title="Comparison",
        height="250px")

    # Works
    tgb.metric(lambda value: value if value else 0,
            delta="{(value - previous_value) if value and previous_value else 0}",
            max=20,
            title="Comparison",
            height="250px")
# Main execution block with GUI setup
if __name__ == "__main__":
    tp.Gui(page).run(title="Bug replication", port=3248)

Browsers

Chrome

OS

Windows

Version of Taipy

Develop - 7/15/24

Acceptance Criteria

Code of Conduct

FlorianJacta commented 1 month ago

This is the same issue as this one: https://github.com/Avaiga/taipy/issues/1518

I will close this issue.