[WEBAPP] How to run a scenario with a local variable
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) ?
Best Answer
-
Sarina Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 317 Dataiker
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
Answers
-
Redouxne Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 4 ✭
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
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,166 Neuron
Please raise a new thread as this is a different question and this thread has been marked as resolved already.