Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Added on January 11, 2024 3:01PM
Likes: 0
Replies: 5
I have a python recipe in my scenario working with a local variable.
I have succesfully executed my scenario within the webapp but :
How can I change the local variable from the webapp's code (in the Python back-end) ?
Hi @Redouxne
,
Are you using a scenario variable or a project variable? Indeed, for scenario variables, it's only possible to set them from within the context of a scenario.
So, if you want to set a variable that will be used in a scenario but set it from a Webapp, you'll probably want to use a project variable instead. You can see the following code example for how to set a variable from the Python API, which can be run in the Python backend.
import dataiku client = dataiku.api_client() project = client.get_default_project() variables = project.get_variables() variables['standard']['some_variable'] = 'some_value' project.set_variables(variables)
Then, from your scenario you can obtain this variable in a Python step:
import dataiku client = dataiku.api_client() project = client.get_default_project() variables = project.get_variables() some_variable_value = variables['standard']['some_variable']
Let me know if this approach doesn't work for you!
Thank you,
Sarina
Hi Sarina,
Thank you ! At first glance it seems to work, I have another question, do you know how to know when the scenario ended and get the information in my Python back-end ?
Thank you again,
Redouane
Please raise a new thread as this is a different question and this thread has been marked as resolved already.
Why are u using -
variables['standard']['some_variable'] = 'some_value'
If my Json structure is simple, Can I use :
variables['some_variable'] = 'some_value'
Even after this if I again print project.get_variables(), it doesnot print any value in my dash webapp
variables = project.get_variables() variables['standard']['some_variable'] = 'some_value' project.set_variables(variables) variables = project.get_variables() #doesnot get any value
Any help is highly appreciated
@sichoudh This thread is already been answered and over a year. Please start a new thread with your question.