Why create an App Panel?
Building an app panel will let other users interact with the code in a more accessible and friendly fashion, by entering or choosing the values for the set of parameters you make available to them.
In this article, we will help you create a simple app panel with the example R script that you can use and adapt to your own code.
Prepare a New Capsule with Sample Files
App Panel works with code files that take input parameters in a capsule.
Create a new capsule using the R starter environment.
Click on Start with Sample Files to generate code and data that are ready for the App Panel.
Set up the Parameters Panel
Set up the Parameters panel to map the input arguments in the code (e.g. main.R) to user inputs in the App Panel.
Click on the App Panel tab on the left (highlighted in red) to enter the Parameters and Result Files panels. The Parameters panel should be unlocked by default.
Types of Parameters
App Panel supports three types of input parameters. The icons at the top of the Parameters panel represent each type:
Text Parameter: allows users to enter any string or number
List Parameter: allows users to select one value from a list
File Parameter: allows users to select an existing file under
/data
folder or upload a file from their local machine
main.R
plots a sine function. You will set up the following three arguments in this example from main.R
.
plot_title
: the title of the figure in the result file.number_of_cycles
: # of cycles for the sine function.input_data
: a txt file that indicates the sampling rate.
The arguments args[x]
in line 9-11 need to match with the three input parameters in the panel in sequential order from top to bottom. The following session shows you how to set the input parameters up respectively.
plot_title
The first parameter value you set up goes to args[1]
in the code. It is stored in plot_title
as the first argument. This parameter lets the viewer type the plot title by entering any text. A Text Parameter is the most appropriate parameter type here.
number_of_cycles
The second parameter value you set up goes to args[2]
, which is stored in number_of_cycles
as the second argument. This parameter lets the viewer choose the number of cycles for the plot. Both Text and List Parameters are suitable here, although using a List Parameter limits users to a list of predefined values.
input_data
The third parameter value you set up goes to args[3]
, which is stored in the variable input_data
as the third argument. This parameter lets the viewer choose the input file under the /data
folder.
Note: Files uploaded to the /data
folder will appear in the drop-down menu.
Lock the Parameters Panel
Now that you set up the parameters, lock the panel so that other users can change the parameters without modifying the settings. Click on the unlock icon to switch the panel to lock mode.
Run with Parameters
After setting up the Parameters panel, click on Run with parameters on the upper right to execute the run
script. Line 8 of the run
file Rscript main.R "$@"
runs the main.R
file with the three parameters you just set up in the parameters panel (see what β$@β stands for).
Set up the Result Files Panel
After you've generated results, click on Add Result File +. Select the result file that you want to display after each run with parameters from the drop-down menu (e.g. fig1.png
and fig2.png
).
Example capsules