-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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] Issue using lambda when passing state variable to a method #2212
Comments
In your community example, the lambda does not work because rng is part of the state and needs to be passed as an argument. With this code, everything works import numpy as np
import taipy.gui.builder as tgb
from taipy import Gui
rng = np.random.default_rng()
size = 1
with tgb.Page() as main_page:
tgb.text(lambda size, rng: rng.random(size).sum() > 0)
with tgb.part(render=lambda size, rng: rng.random(size).sum() > 0):
tgb.text("Random sum is greater than 0")
if __name__ == "__main__":
gui = Gui(main_page)
gui.run(title="2212 [🐛 BUG] Issue using lambda when passing state variable to a method") |
I guess it would be the same thing for your enterprise example, if you declare I would agree that a better error message would be good |
I can confirm that adding I noticed that I could have created a variable like |
I don't get it about rngrandom, can you copy your code ? |
Following (ugly) workaround works: import numpy as np
import taipy.gui.builder as tgb
from taipy import Gui
rng = np.random.default_rng()
size = 1
with tgb.Page() as main_page:
rngrandom = rng.random
tgb.text(lambda size: rngrandom(size).sum())
if __name__ == "__main__":
gui = Gui(main_page)
gui.run() It is ugly and I don't like it, but it gives intellisense for the You mentioned "re-created on the fly with the value of rng at first render", but I don't really know what that means. I'm wondering if there may be unexpected behavior when doing this, as opposed to adding |
no unexpected behavior that I can see/imagine |
Shall we close this @arcanaxion ? |
@FredLL-Avaiga I would still like to see a better error message, if it makes sense to do so. I wouldn't have figured out what the problem was from the current error message |
fixed it |
What went wrong? 🤔
I'm trying to use a lambda function in tgb.part.render with a role trait filter to hide something based on a user's credentials:
I get the following error:
There is nothing shown on the webpage -- the tgb.text before the part block is also not shown.
Alternate community example
This code also does not work -- nothing is displayed on the webpage:
With 4.0, the error is not printed in the console. I guess this is related to #2144.
With develop, I get the following error:
Expected Behavior
The lambda expressions should evaluate to true and the block should be rendered.
Browsers
Chrome
OS
Windows, Linux
Version of Taipy
taipy-enterprise==4.0.0; develop
Additional Context
Acceptance Criteria
Code of Conduct
The text was updated successfully, but these errors were encountered: