Skip to main content

Automate inputs

Autocomplete values

Use parameter suggestions to help users enter a correct value. For instance, when entering a product name, it might make sense to dynamically query a database for values starting with the already entered text, and suggest to auto-complete the value.

Suggestions are functions that take one string argument, and return a list of strings to be suggested to user. Suggestions work only for string parameters.

The following example helps user enter a country name by dynamically retrieving a list of names from a web service:

script-param-suggestions

The same concept could be used for SQL queries:

auto-complete-sql

Precalculate inputs

Use parameter editor to set the output of another function to the parameter value.

//input: dataframe table {editor: Package:DataQuery}
//input: dataframe table {editor: Package:DataQuery(1, "France")}

Here, Datagrok will execute the Package:DataQuery function right before your script and pass the output table to the script as an input parameter.

//input: dataframe table {editor: PowerPack:DataQuery; editor-button: Outliers...}

Specify the editor-button parameter to add a button that executes your subfunction separately and allows the user to check the output before starting the script.

Suggest choices

Use choices to provide the editor a list of values to choose from. When choices are provided, the editor becomes a combo box. Choices can be either a fixed list, or a function that returns a list.

A choice provider is a function with no parameters that returns a list of strings.

The following example demonstrates two ways of defining choices:

script-param-choices

Validate inputs

Validators check whether the value falls in the expected range, and provide visual cue if it does not. To add a validator to a parameter, provide a comma-separated list of functions that will be invoked each time a value is changed. A null indicates that the value is valid, anything else indicates an error which gets shown to the user.

A validator is a function that accepts one parameter of any type and returns a string. Choice providers are applicable only to string parameters.

script-param-validators