Apache Zeppelin is a fantastic open source web-based software that allows users to build and share great looking data visualizations using various languages. If you aren’t familiar with using the shell interpreter in Apache Zeppelin, see our related post Creating Graphs with the Zeppelin Shell Interpreter.

Apache Zeppelin allows dynamic creation of text input forms in your notebooks. Input forms can be created and referenced using a simple template language. For example, using ${variable_name} in a shell script will reference the value in the associated input form (in this case the “variable_name” input form). If this text input form does not already exist, Zeppelin will add it to your notebook. To set a default value for a text input form, use the ${variable_name=value} syntax.

Using a Text Input Form in Shell Scripts

Here is an example running a shell script on NBA data that references the value in the “Team Name” input form. Notice that the default value for this form is “Jazz” but we have since changed this value to “Bulls”.

%sh

echo "%table"

#create header
echo -e "Year\tTotal Points" > outputfile.txt

#generate output data
cat /data/data/nba-elo/nba-elo.csv \
  | tr ',' '\t' \
  |  awk '{FS="\t"; OFS="\t"}  $10 == "${Team Name=Jazz}" {arr[$5]+=$11} END{for(x in arr) print x, arr[x]}' \
  | sort \
  >> outputfile.txt
 
#display output 
cat outputfile.txt

Using Multiple Text Input Forms in Shell Scripts

Zeppelin allows the dynamic creation of many input forms in each notebook. Here is an example of running a shell script that references the values of multiple input forms (“Team Name” and “Start Year”):

%sh

echo "%table"

#create header
echo -e "Year\tTotal Points" > outputfile.txt

#generate output data
cat /data/data/nba-elo/nba-elo.csv \
  | tr ',' '\t' \
  |  awk '{FS="\t"; OFS="\t"}  $10 == "${Team Name=Jazz}" && $5 >= ${Start Year=1995} {arr[$5]+=$11} END{for(x in arr) print x, arr[x]}' \
  | sort \
  >> outputfile.txt
 
#display output 
cat outputfile.txt

Leave a Reply

Using Input Forms with Shell Scripts – Apache Zeppelin