Groovy Interpreter for Apache Zeppelin


//get a parameter defined as z.angularBind('ngSearchParam', value, 'paragraph_id')
//g is a context object for groovy to avoid mix with z object
def param = g.angular('ngSearchParam')
//send request
def r = HTTP.get(
  //assume you defined the groovy interpreter property
  //   `search_baseurl`=''
  //in groovy object o.getProperty('A') == o.'A' == o.A == o['A']
  url : g.search_baseurl,
  query: [ q: param ],
  headers: [
    //'Authorization:' : g.getProperty('search_auth'),
  ssl : g.getProperty('search_ssl') // assume groovy interpreter property search_ssl = HTTP.getNaiveSSLContext()
//check response code
if( r.response.code==200 ) {
    //g.html() renders %angular to output and returns groovy.xml.MarkupBuilder
    h2("the response ${r.response.code}")
    span( r.response.body )
    pre( r.response.headers.join('\n') )
} else {
  //just to show that it's possible to use println with multiline groovy string to render output
    <script> alert ("code=${r.response.code} \n msg=${r.response.message}") </script>

//renders a table with headers a, b, c  and two rows

the g object

  • g.angular(String name)

    Returns angular object by name. Look up notebook scope first and then global scope.

  • g.angularBind(String name, Object value)

    Assign a new value into angular object name

  • java.util.Properties g.getProperties()

    returns all properties defined for this interpreter

  • String g.getProperty('PROPERTY_NAME')


    All above the accessor to named property defined in groovy interpreter. In this case with name PROPERTY_NAME

  • groovy.xml.MarkupBuilder g.html()

    Starts or continues rendering of %angular to output and returns groovy.xml.MarkupBuilder MarkupBuilder is usefull to generate html (xml)

  • void g.table(obj)

    starts or continues rendering table rows.

    obj: List(rows) of List(columns) where first line is a header

  • g.input(name, value )

    Creates text input with value specified. The parameter value is optional.

  •, default, Map<Object, String> options)

    Creates select input with defined options. The parameter default is optional.'sex', 'm', ['m':'man', 'w':'woman'])

  • g.checkbox(name, Collection checked, Map<Object, String> options)

    Creates checkbox input.

  • g.get(name, default)

    Returns interpreter-based variable. Visibility depends on interpreter scope. The parameter default is optional.

  • g.put(name, value)

    Stores new value into interpreter-based variable. Visibility depends on interpreter scope.