Navot Naor
Navot Naor

Reputation: 91

Bokeh widget not showing

I am taking my first steps at creating a bokeh interactive visualization app, and I am trying to create a few dropdown menus for data selection.

Before implementing it on my own data I've tried reproducing widgets from the Bokeh tutorial.

My code

from math import pi

import pandas as pd

from bokeh.palettes import Category20c
from bokeh.plotting import figure
from bokeh.transform import cumsum
from bokeh.io import show, output_file, output_notebook, curdoc
from bokeh.models import ColumnDataSource, Select
from bokeh.layouts import widgetbox
from bokeh.resources import INLINE
import bokeh.io

bokeh.io.output_notebook(INLINE)


# Create two dropdown Select widgets: select1, select2
select1 = Select(title="First", options=["A", "B"], value="A")
select2 = Select(title="Second", options=["1", "2", "3"], value="1")

# Define a callback function: callback
def callback(attr, old, new):
    # If select1 is 'A'
    if select1.value == "A":
        # Set select2 options to ['1', '2', '3']
        select2.options = ["1", "2", "3"]

        # Set select2 value to '1'
        select2.value = "1"
    else:
        # Set select2 options to ['100', '200', '300']
        select2.options = ["100", "200", "300"]

        # Set select2 value to '100'
        select2.value = "100"


# Attach the callback to the 'value' property of select1
select1.on_change("value", callback)

# Create layout and add to current document
layout = widgetbox(select1, select2)
curdoc().add_root(layout)

After excepting the code all I get is a warning, but I see nothing.

enter image description here

What am I doing wrong?

Thank you

p.s. I know I am calling a lot more then I need, I would use all packages later on, or just remove them.

Upvotes: 0

Views: 1417

Answers (1)

djangoliv
djangoliv

Reputation: 1788

You can replace WidgetBox with Column to avoid the warning, but the real problem is that you don't display anything.

Add "show(layout)" at the end of the notebook if you want to display it.

Upvotes: 1

Related Questions