### What is this PR for? Added dynamic forms for Note. All paragraphs has access to note forms. ### What type of PR is it? [Feature] ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-1363 ### How should this be tested? Create global interpreter JDBC and Spark. Create note with 2 paragraphs ``` %pyspark print("Textbox paragraph " + z.textbox('input', 'default')) print("Textbox note " + z.noteTextbox('note_input', 'default_note')) print("Select paragraph " + z.select("sel", [("1","opt1"), ("2","opt2"), ("3","opt3")])) print("Select note " + z.noteSelect("sel_note", [("1","noteOpt1"), ("2","noteOpt2"), ("3","noteOpt3")])) options = [("key1","Name1"), ("key2","Name2")] print("Checkbox paragraph "+ " and ".join(z.checkbox("chk", options, ["key1"]))) print("Checkbox note "+ " and ".join(z.noteCheckbox("chk_note", options, ["key1","key2"]))) ``` ``` %jdbc select '$${checkbox:chk_note=key1|key2,key1|key2} $${note_input} ${note_input=sameName}' ``` ### Screenshots (if appropriate) 1) native forms  2) remove  3) simple forms  ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: tinkoff-dwh <tinkoff.dwh@gmail.com> Closes #2641 from tinkoff-dwh/ZEPPELIN-1363 and squashes the following commits:3ee4826[tinkoff-dwh] [ZEPPELIN-1363] autosave textboxf30033a[tinkoff-dwh] Merge remote-tracking branch 'upstream/master' into ZEPPELIN-136329eaca2[tinkoff-dwh] [ZEPPELIN-1363] fix testsbf8194e[tinkoff-dwh] Merge remote-tracking branch 'upstream/master' into ZEPPELIN-13639b2f3e9[tinkoff-dwh] [ZEPPELIN-1363] button to remove formc566462[tinkoff-dwh] [ZEPPELIN-1363] note dynamic forms (simple; native: spark, python)
6.8 KiB
| layout | title | description | group |
|---|---|---|---|
| page | Dynamic Form in Apache Zeppelin | Apache Zeppelin dynamically creates input forms. Depending on language backend, there're two different ways to create dynamic form. | usage/dynamic_form |
{% include JB/setup %}
What is Dynamic Form?
Apache Zeppelin dynamically creates input forms. Depending on language backend, there're two different ways to create dynamic form. Custom language backend can select which type of form creation it wants to use. Forms can have different scope (paragraph or note). Forms with scope "note" available in all paragraphs regardless of which paragraph has code to create these forms.
Using form Templates (scope: paragraph)
This mode creates form using simple template language. It's simple and easy to use. For example Markdown, Shell, Spark SQL language backend uses it.
Text input form
To create text input form, use ${formName} templates.
for example
Also you can provide default value, using ${formName=defaultValue}.
Select form
To create select form, use ${formName=defaultValue,option1|option2...}
for example
Also you can separate option's display name and value, using ${formName=defaultValue,option1(DisplayName)|option2(DisplayName)...}
The paragraph will be automatically run after you change your selection by default. But in case you have multiple types dynamic form in one paragraph, you might want to run the paragraph after changing all the selections. You can control this by unchecking the below Run on selection change option in the setting menu.
Even if you uncheck this option, still you can run it by pressing Enter.
Checkbox form
For multi-selection, you can create a checkbox form using ${checkbox:formName=defaultValue1|defaultValue2...,option1|option2...}. The variable will be substituted by a comma-separated string based on the selected items. For example:
You can specify the delimiter using ${checkbox(delimiter):formName=...}:
Like select form, the paragraph will be automatically run after you change your selection by default. But in case you have multiple types dynamic form in one paragraph, you might want to run the paragraph after changing all the selections. You can control this by unchecking the below Run on selection change option in the setting menu.
Even if you uncheck this option, still you can run it by pressing Enter.
Using form Templates (scope: note)
Has a same syntax but starts with two symbols $. (for ex. input $${forName})
Creates Programmatically (scope: paragraph)
Some language backends can programmatically create forms. For example ZeppelinContext provides a form creation API
Here are some examples:
Text input form
{% highlight scala %} %spark println("Hello "+z.textbox("name")) {% endhighlight %}
</div>
<div data-lang="python" markdown="1">
{% highlight python %} %pyspark print("Hello "+z.textbox("name")) {% endhighlight %}
</div>
Text input form with default value
{% highlight scala %} %spark println("Hello "+z.textbox("name", "sun")) {% endhighlight %}
</div>
<div data-lang="python" markdown="1">
{% highlight python %} %pyspark print("Hello "+z.textbox("name", "sun")) {% endhighlight %}
</div>
Select form
{% highlight scala %} %spark println("Hello "+z.select("day", Seq(("1","mon"), ("2","tue"), ("3","wed"), ("4","thurs"), ("5","fri"), ("6","sat"), ("7","sun")))) {% endhighlight %}
</div>
<div data-lang="python" markdown="1">
{% highlight python %} %pyspark print("Hello "+z.select("day", [("1","mon"), ("2","tue"), ("3","wed"), ("4","thurs"), ("5","fri"), ("6","sat"), ("7","sun")])) {% endhighlight %}
</div>
Checkbox form
{% highlight scala %} %spark val options = Seq(("apple","Apple"), ("banana","Banana"), ("orange","Orange")) println("Hello "+z.checkbox("fruit", options).mkString(" and ")) {% endhighlight %}
</div>
<div data-lang="python" markdown="1">
{% highlight python %} %pyspark options = [("apple","Apple"), ("banana","Banana"), ("orange","Orange")] print("Hello "+ " and ".join(z.checkbox("fruit", options, ["apple"]))) {% endhighlight %}
</div>
Creates Programmatically (scope: note)
The difference in the method names:
| Scope paragraph | Scope note |
|---|---|
| input (or textbox) | noteTextbox |
| select | noteSelect |
| checkbox | noteCheckbox |