-
Notifications
You must be signed in to change notification settings - Fork 690
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
Make Python expression in Viz elements more Pythonic in Python API #1379
Comments
we don't support function as variable |
You can introspect the variable names of the lambda function so you know data is a bound variable then call the function with the state variables bound to it. I don't say it is possible now obviously. |
A vast improvement is that you can tell Taipy which variables are interactive inside the lambda function, making it easy to create this kind of code. Current version: for key in list_of_keys:
tgb.text("{str(message['"+key+"'])}")
# don't forget the ' otherwise this will not work, and Python autocompletion, correction won't help you
# you cannot also use the " as it is already used; this is really error-prone This is much better: for key in list_of_keys:
tgb.text(lambda message: str(message[key])) message here is the bound variable of the Taipy expression, key is not and can be present in the state without a problem. This is a huge improvement in Taipy with the Python API, as I and users have encountered it frequently. |
I like the idea. It is less error-prone than coding into strings. |
From what I understand, one would need to generate intermediate code that would look like:
|
good news: we can support lambdas
Which will translate into the equivalent of
bad news: I don"t think there's a way that we can support using external variables in lambda (it works but it is always the last value that is used)
Will render as
This because the render is not synchronous with the declaration ie at render time In that case, I wonder if the lambda support is still interesting ? |
PS: I can push the code in a branch if someone wants to play with it |
That's wonderful @FredLL-Avaiga. The limitation is pretty bad though. |
I'm afraid we cannot render at build time :-( |
Description
Make Python expressions inside the Python API more Pythonic.
Markdown text is hard to debug, with no autocompletion, syntax coloring, etc. It is error-prone and is not easy to use when using for loops (see below).
Solution Proposed
Use lambda function instead of Python inside Markdown text.
A vast improvement is that you can tell Taipy which variables are interactive inside the lambda function, making creating this kind of code easy.
Current version:
This is much better:
message here is the bound variable of the Taipy expression, key is not and can be present in the state without a problem.
Impact of Solution
This could impact the product, but we should keep Python expressions inside Markdown as they are done now.
Code of Conduct
The text was updated successfully, but these errors were encountered: