Create Programmatic Dynamic Forms

Graph Studio allows you to programmatically create dynamic forms using the Java (PGX) and Python (PGX) interpreters.

You can pass dynamic values (such as variables, arrays, and so on) through Java or Python code to generate dynamic forms.

As a prerequisite step, you must first import and instantiate the context to use programmatic dynamic forms.

import oracle.datastudio.interpreter.common.context.JavaDataStudioContext
JavaDataStudioContext ds = interpreter.getJavaDataStudioContext()
from ds_interpreter_client.context.ds_context import PyDataStudioContext
ds = PyDataStudioContext()
The ds context allows you to display the forms and define your own variable name.

The following steps describe the programmatic creation of the Textbox, Select, Slider, Checkbox, Date Picker, Time Picker, and DateTime Picker forms.

  • Create a Textbox dynamic form which allows you to input any string of characters.
    ds.textbox("<name>", "<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • default_value (optional): The default value that is given to the dynamic form when it is first created.

    For example:

    Description of java_text_box.png follows
    Description of the illustration java_text_box.png
    ds.textbox(name="<name>", default_value="<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • default_value (optional): The default value that is given to the dynamic form when it is first created.

    For example:

    Description of python_text_box.png follows
    Description of the illustration python_text_box.png
  • Create a Select dynamic form which allows you to select a value from a drop-down menu.
    import oracle.datastudio.common.forms.ParamOption
    List<ParamOption<String>> options = new ArrayList<>()
    options.add(new ParamOption<>("<option_value_a>", "<option_label_a>"))
    options.add(new ParamOption<>("<option_value_b>", "<option_label_b>"))
    ds.select("<name>", options, "<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • default_value (optional): The default value that is given to the dynamic form when it is first created.

    For example:

    Description of java_select.png follows
    Description of the illustration java_select.png
    options = [("<option_value_a>", "<option_label_a>"),("<option_value_b>", "<option_label_b>")]
    ds.select(name="<name>", options=options, default_value="<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • default_value (optional): The default value that is given to the dynamic form when it is first created.

    For example:

    Description of python_select.png follows
    Description of the illustration python_select.png
  • Create a Slider dynamic form which allows you to choose a number from a given range.
    ds.slider("<name>", <minimum>, <maximum>, <step_size>, <default_value>)

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • minimum: The minimum value of the slider. Must be a number.
    • maximum: The maximum value of the slider. Must be a number.
    • step_size: The step size of the slider. Must be a number and divider of (maximum - minimum).
    • default_value (optional): The default value that is given to the dynamic form when it is first created (minimum <= default_value <= maximum).

    For example:

    Description of java_slider.png follows
    Description of the illustration java_slider.png
    ds.slider(name="<name>", min=<minimum>, max=<maximum>, step=<step_size>, default_value=<default_value>)

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • minimum: The minimum value of the slider. Must be a number.
    • maximum: The maximum value of the slider. Must be a number.
    • step_size: The step size of the slider. Must be a number and divider of (maximum - minimum).
    • default_value (optional): The default value that is given to the dynamic form when it is first created (minimum <= default_value <= maximum).

    For example:

    Description of python_slider.png follows
    Description of the illustration python_slider.png
  • Create a Checkbox dynamic form which allows you to select one or multiple values.
    import oracle.datastudio.common.forms.ParamOption
    
    List<ParamOption<String>> options = new ArrayList<>()
    options.add(new ParamOption<>("<option_value_a>", "<option_label_a>"))
    options.add(new ParamOption<>("<option_value_b>", "<option_label_b>"))
    List<String> defaultValues = new ArrayList<>()
    defaultValues.add("<default_value>")
    ds.checkbox("<name>", options, defaultValues)

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • default_value (optional): The default value that is given to the dynamic form when it is first created.

    For example:

    Description of java_checkbox.bmp follows
    Description of the illustration java_checkbox.bmp
    options = [("<option_value_a>", "<option_label_a>"),("<option_value_b>", "<option_label_b>")]
    ds.checkbox(name="<name>", options=options, default_value=["<default_value>"])

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • default_value (optional): The default value that is given to the dynamic form when it is first created.

    For example:

    Description of python_checkbox.png follows
    Description of the illustration python_checkbox.png
  • Create a Date Picker dynamic form which allows you to select a date.
    ds.datePicker("<name>", "<date_format>", "<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • date_format (optional, recommended): The date format that is used for displaying the selected date in the input field and for formatting the resulting date when the paragraph is run.
    • default_value (optional): The default value that is given to the dynamic form when it is first created. It must be specified according to the date_format or in yyyy-MM-dd format if the date_format is not provided.

    For example:

    Description of java_date.png follows
    Description of the illustration java_date.png
    ds.date_picker(name="<name>", format="<date_format>", default_value="<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • date_format (optional, recommended): The date format that is used for displaying the selected date in the input field and for formatting the resulting date when the paragraph is run.
    • default_value (optional): The default value that is given to the dynamic form when it is first created. It must be specified according to the date_format or in yyyy-MM-dd format if the date_format is not provided.

    For example:

    Description of python_date_picker.png follows
    Description of the illustration python_date_picker.png
  • Create a Time Picker dynamic form which allows you to select a time.
    ds.timePicker("<name>", "<time_format>", "<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • time_format (optional, recommended): The time format that is used for displaying the selected time in the input field and for formatting the resulting time when the paragraph is run.
    • default_value (optional): The default value that is given to the dynamic form when it is first created. It must be specified according to the time_format or in HH:mm format if the time_format is not provided.

    For example:

    Description of java_time.png follows
    Description of the illustration java_time.png
    ds.time_picker(name="<name>", format="<time_format>", default_value="<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • time_format (optional, recommended): The time format that is used for displaying the selected time in the input field and for formatting the resulting time when the paragraph is run.
    • default_value (optional): The default value that is given to the dynamic form when it is first created. It must be specified according to the time_format or in HH:mm format if no time_format is provided.

    For example:

    Description of python_time_picker.png follows
    Description of the illustration python_time_picker.png
  • Define a DateTime Picker dynamic form which allows you to select a date and a time.
    ds.dateTimePicker("<name>", "<dateTime_format>", "<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • dateTime_format (optional, recommended): The dateTime format that is used for displaying the selected date and time in the input field and for formatting the resulting date and time when the paragraph is run.
    • default_value (optional): The default value that is given to the dynamic form when it is first created. It must be specified according to the dateTime_format or in yyyy-MM-dd HH:mm format if the dateTime_format is not provided.

    For example:

    Description of java_date_time.png follows
    Description of the illustration java_date_time.png
    ds.date_time_picker("<name>", format="<dateTime_format>", default_value="<default_value>")

    In the preceding code:

    • name: The name of the dynamic form. It is displayed on top of the dynamic form. If you want to reference a dynamic form multiple times in a paragraph, you can assign the same name to do so and it will only be displayed once.
    • dateTime_format (optional, recommended): The dateTime format that is used for displaying the selected date and time in the input field and for formatting the resulting date and time when the paragraph is run.
    • default_value (optional): The default value that is given to the dynamic form when it is first created. It must be specified according to the dateTime_format or in yyyy-MM-dd HH:mm format if the dateTime_format is not provided.

    For example:

    Description of python_date_time_picker.png follows
    Description of the illustration python_date_time_picker.png