zjffdu / bkzep

Python package for using bokeh in Apache Zeppelin Notebook
10 stars 1 forks source link

bokeh app not showing in zeppelin #8

Open qh582 opened 6 years ago

qh582 commented 6 years ago

Hi, I'm new to Zeppelin and Bokeh. I am unable to plot bokeh app in the notebook with the following code. I get the "BokehJS 0.12.14 successfully loaded." message, but no plot.

import yaml
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
from bokeh.themes import Theme
from bokeh.io import show, output_notebook
from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature

import bkzep
output_notebook(notebook_type='zeppelin')

def modify_doc(doc):
    df = sea_surface_temperature.copy()
    source = ColumnDataSource(data=df)

    plot = figure(x_axis_type='datetime', y_range=(0, 25),
                  y_axis_label='Temperature (Celsius)',
                  title="Sea Surface Temperature at 43.18, -70.43")
    plot.line('time', 'temperature', source=source)

    def callback(attr, old, new):
        if new == 0:
            data = df
        else:
            data = df.rolling('{0}D'.format(new)).mean()
        source.data = ColumnDataSource(data=data).data

    slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days")
    slider.on_change('value', callback)

    doc.add_root(column(slider, plot))

    doc.theme = Theme(json=yaml.load("""
        attrs:
            Figure:
                background_fill_color: "#DDDDDD"
                outline_line_color: white
                toolbar_location: above
                height: 500
                width: 800
            Grid:
                grid_line_dash: [6, 4]
                grid_line_color: white
    """))

handler = FunctionHandler(modify_doc)
app = Application(handler)
show(app, notebook_url='*')

I'm wondering if I miss something, as the code works fine in jupyter-notebook by changing notebook_type. Thank you.

zjffdu commented 6 years ago

Do you mind to try bokeh 0.12.13, I haven't verified bokeh 0.12.14

zjffdu commented 6 years ago

I just tried it in and it works for me.

screen shot 2018-02-11 at 8 16 48 pm

zjffdu commented 6 years ago

BTW, showing bokeh app is only supported in %python.ipython which is supported in zeppelin 0.8. zeppelin 0.8 will be released soon.

qh582 commented 6 years ago

@zjffdu Thanks. I will follow up the new zeppelin release.