Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 BUG] Scope issue with lambda function #2242

Closed
1 of 7 tasks
FlorianJacta opened this issue Nov 13, 2024 · 4 comments · Fixed by #2250
Closed
1 of 7 tasks

[🐛 BUG] Scope issue with lambda function #2242

FlorianJacta opened this issue Nov 13, 2024 · 4 comments · Fixed by #2250
Assignees
Labels
🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟥 Priority: Critical Must be addressed as soon as possible

Comments

@FlorianJacta
Copy link
Member

FlorianJacta commented Nov 13, 2024

What went wrong? 🤔

There are issues using the lambda functions with multiple pages.

C:\Users\jacta\.conda\envs\test\Lib\site-packages\taipy\gui\utils\_evaluator.py:369: TaipyGuiWarning: Exception raised evaluating __lambda_2466438897376_1_TPMDL_0(x):

name 'create_chart' is not defined
  _warn(f"Exception raised evaluating {expr_string}", e)

(Note that this issue was first seen when trying to have multiple states for an application; this might not be the same issue)

Expected Behavior

This should work fine like the comments in the code example.

Steps to Reproduce Issue

app.py

from taipy import Gui
from page_py import page # if you add 'create_chart' in the import, then this works!

pages = {"/": "App", "page": page}

Gui(pages=pages).run()

page_py.py

import taipy.gui.builder as tgb
import pandas as pd
import plotly.express as px

x = 0


def create_chart(x):
    print("Hello")
    df = pd.DataFrame(
        {
            "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
            "Amount": [4, 1, 2, 2, 4, 5],
            "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"],
        }
    )
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    fig.show()
    return fig


with tgb.Page() as page:
    tgb.text("Hello World")
    tgb.slider("{x}")
    tgb.chart(figure=lambda x: create_chart(x))

    # If you use the Markdown syntax, there are no issues. This works
    # tgb.chart(figure="{create_chart(x)}")

Browsers

Chrome

OS

Windows

Version of Taipy

4.0.1

Acceptance Criteria

  • A unit test reproducing the bug is added.
  • Any new code is covered by a unit tested.
  • Check code coverage is at least 90%.
  • The bug reporter validated the fix.
  • Related issue(s) in taipy-doc are created for documentation and Release Notes are updated.

Code of Conduct

  • I have checked the existing issues.
  • I am willing to work on this issue (optional)
@FlorianJacta
Copy link
Member Author

Should this be backported?

@FredLL-Avaiga
Copy link
Member

Should this be backported?

Was it supported and documented in 3.1?
Is it a regression?

@FlorianJacta
Copy link
Member Author

Is that the criteria to be backported?

It was working in 4.0.dev1 for example; I don't know if this is called a regression. Zacch had the same issue when writing its application

FabienLelaquais added a commit that referenced this issue Dec 17, 2024
* Backport to 4.0 of Taipy GUI issues #2212, #2242, #2281, #2286, #2302, and #2305.
* Upgrade JS bundles versions to 4.0.2
@FlorianJacta
Copy link
Member Author

FlorianJacta commented Dec 18, 2024

Fixed in 4.0.2.dev1. I will test if this fixes my original issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟥 Priority: Critical Must be addressed as soon as possible
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants