What are live task ?
Python live tasks are tasks that allow you to execute any Python or R code snippets on the fly. You can write custom code that modifies a Table, generate a chart or call an external library directly in a task. Live task can be easily developed modified and shared. In their config they include a some parameter and a light version of a IDE to code directly in your lab.
Here is a simple python live task that transpose a Table
.
Warning: It is recommended to use code snippets coming from trusted sources.
Types
There 2 type of live tasks that can answer different problematics.
Basic python live task
This is the simplest live task that allows you to write python code that takes resources as input and return resources. It only supports python code and already installed package. It can be useful to manipulate an existing resource.
See the following link for more information : https://constellab.community/tech-doc/doc/developer-guide/live-task/python-live-task
Virtual env live task
Virtual en live task allows you to execute live task code in virtual environment. With this you can use a Pip
, Conda
or an Conda R
environment. Virtual env live task takes a mandatory parameter that define the virtual environment.
As they use virtual environment to be executed, theses live task can only take File
,Folder
or ResourceSet
as input/output. Theses live task are not run in the context of a normal Task
.
See the following link for more information : https://constellab.community/tech-doc/doc/developer-guide/live-task/python-live-task
Parameters
You can define parameter in the live task so it is more re-usable and theses can be modified by a person not used to code. Here is a example of parameters.
This will be directly added to you live task code automatically. It must respect the syntax of the live task language (Python or R).
Note: If an exception occurred, the line number the exception tells will not be exact if you defined parameters. There will be one more line per parameter in the generated code. So if you have 2 parameters and the error tells you that there is a problem line 12, it correspond to line 10 of your code in live task.
Managing inputs and outputs
The inputs and outputs of the live task are dynamic, which means you can add or remove them manually. The task takes in a list of resources as input and gives back another list of resources as output.
To add an input or output, go to the Dashboard of the task and click the '+' button under the inputs or outputs list. You can also remove them by clicking the 'x' button.
Note: you can also add inputs and outputs in the inputs and outputs section of the task in the right panel.
Make sure the length of the target matches the number of outputs your task needs.
Troubleshoot
To many resources in output target, expected X got Y
This error tells you that the targets
array size is bigger than the number of output created in the interface. Please follow the Managing inputs and outputs section above to see how to create new output. The length of the targets
array must be equals to the number of output in the live task.