You can utilize values entered by users from the UI in SQL and Python processes in data applications.

  • When using the load_data function to chain processes, all variables are passed to all processes.
  • Variables can be passed to SQL and Python from MDX using the variables argument as shown below.

export const dateRangeStart = variable(undefined);
export const dateRangeEnd = variable(undefined);

{/* UI Component to enter values into variables */}

<DataTable
	alias="get_stock_data"
	variables={{
		start_date: dateRangeStart,
		end_date: dateRangeEnd
	}}
/>

The argument is actually executed with the following command in Morph’s CLI. If executed in the Code tab, this argument is not added, so you need to specify the default value.

You can specify variables with -d as follows.

Shell
morph run get_users -d user_type=admin

Use Variables in SQL/Python

Variables are passed to SQL as arguments enclosed in {{ }} in Jinja format.

{{
	config(
		name="get_users",
	)
}}

{% if user_type %}
select * from user where user_type = '{{ user_type }}'
{% else %}
select * from user
{% endif %}