Reputation: 3587
Is it possible to display Bokeh charts inline in Zeppelin using the Pyspark interpreter?
In Jupiter for instance this could be done using the command output_notebook()
to load bokeh js.
Here is an example to produce a simple line chart.
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
# create a new plot
p = figure(plot_width=400, plot_height=400, title="Simple Line Plot")
# add a line renderer
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)
show(p) # show the results
Upvotes: 3
Views: 2422
Reputation: 2897
If you're using Bokeh >= 0.12.7 you can use Jeff Zhang's bkzep
package. E.g., do this outside Zeppelin:
pip install bkzep
Then, as it says at https://github.com/zjffdu/bkzep#how-to-use, you just do this in a Zeppelin notebook bound to the Spark interpreter group:
from bokeh.io import output_notebook
import bkzep
output_notebook(notebook_type='zeppelin')
Then you should be able to see Bokeh plots inline in your notebook. I can confirm this works in Zeppelin 0.7.0 using Bokeh 0.12.13. Example:
Upvotes: 2
Reputation: 2862
I needed chord plot for my project and succesfully adapted bokeh sample to run both in pyspark and in python interpreters in Zeppelin. Support for Zeppelin still needs some love, but works well enough for my purposes.
%pyspark
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
from bokeh.charts import Chord
from bokeh.io import show, output_file, output_notebook
from bokeh.sampledata.les_mis import data
nodes = data['nodes']
links = data['links']
nodes_df = pd.DataFrame(nodes)
links_df = pd.DataFrame(links)
source_data = links_df.merge(nodes_df, how='left', left_on='source', right_index=True)
source_data = source_data.merge(nodes_df, how='left', left_on='target', right_index=True)
source_data = source_data[source_data["value"] > 5] # Select those with 5 or more connections
chord_from_df = Chord(source_data, source="name_x", target="name_y", value="value")
#output_file('chord_from_df.html')
output_notebook(notebook_type='zeppelin')
show(chord_from_df)
Upvotes: 0
Reputation: 76
Actually registered to post this - I'm attempting to get this to work, but running into some interesting issues.
It appears that the Bokeh notebook output depends on IPython notebook, which zeppelin may not.
For the static output, a lot of the resources that are common to IPython notebook are not readily available in Zeppelin.
I'm attempting a workaround here that may end up functional though - Zeppelin has some Angular mark-up that might be used for rendering the Bokeh HTML files.
I just got it inline with the following:
s = "%html "
txt = open('log_lines.html').read()
s += txt
print(s)
Edit: It looks like you still have to call show() on your graph/object to create the file to show. This doesn't appear to create an error, but I'm fairly new to Bokeh still.
Upvotes: 2