Passing App Panel's Parameters to the Script
Was this helpful?
Was this helpful?
When running a Capsule in Code Ocean, the system looks for and executes the Run file. The Run file is a bash script that can be auto-generated by the system and modified manually afterward.
For example, the screenshot below shows the Run script of a sample file provided by Code Ocean.
The Run script is auto-generated and it calls the main.R
on line 8 with the "$@"
parameter, which indicates to pass all the parameters to the script.
The way to access the parameters as command-line arguments in the main script can vary, depending on the programming language and the method of the parameter.
In addition to the label of the Named Parameter, these parameters can also be named. This name will be recognized in the Capsule code, and defaults can be set directly in the App Builder, eliminating the need for a config file to parse the App Panel input.
The name of the parameter is indicated in the [brackets]. Below, an example parameter is named plot_title
.
Ordered Parameters are selected by default. In this method, the arguments will be passed in order. All the sample scripts accommodate this method and can be easily modified to fit your script.
From the above example, the command in R for accessing the command line arguments is in line 5. It reads all the arguments and saves it in the args
variables to access later in line 9 to line 11.
In the App Builder section, the number of the order of the parameter is indicated within the parentheses ().
The Named Parameter version of the sample script for Python with comments for the purpose of each step is below. See Python's for more details.