Zeppelin - pass a variable from Spark to Markdown to create dynamic descriptive text

Is it possible to pass a variable from a Spark interpreter (pyspark or sql) to Markdown? The requirement is to display well-formatted text (for example, Markdown), for example "20 events that occurred between 2017-01-01 and 2017-01-08", where 20, 2017-01-01 and 2017-01-08 are dynamically populated based on the results of other items.

+4
source share
1 answer

Conducting this for other users, this is what I could find:

  • Markdown clauses can only contain static text.
  • However, instead of dynamically formatted text output, you can use the Angular interpreter.

( )

%spark
// create data frame
val eventLogDF = ... 
// register temp table for SQL access
eventLogDF.registerTempTable( "eventlog" )

val query = sql( "select max(Date), min(Date), count(*) from eventlog" ).take(1)(0)
val maxDate = query(0).toString()
val minDate = query(1).toString()
val evCount = query(2).toString()

// bind variables which can be accessed from angular interpreter 
z.angularBind( "maxDate", maxDate )
z.angularBind( "minDate", minDate )
z.angularBind( "evCount", evCount ) 

( )

%angular

<div>There were <b>{{evCount}} events</b> between <b>{{minDate}}</b> and <b>{{maxDate}}</b>.</div>
+5

Source: https://habr.com/ru/post/1666225/


All Articles