Personalized bokeh crossfilter graph does not display

I implemented the crossfilter graph with our data. Issue faced - When outputting the result with bokeh.io.show method, I get the desired graph but with no interactions possible. However if I run the script as a bokeh application using “bokeh serve script.py --show”, I get a blank webpage. I tried figuring out the issue for quite a while but still cannot identify what might possibly be the problem. The script works fine with the bokeh team’s sample data though. Any suggestions would really be helpful.

Note:- Our data does not have any integer or float values. Hence I have commented out the continuous and quantileable parts from the original example code.

ont_res_csv.txt (6.82 KB)

crossfilter_graph.txt (3.38 KB)

Hello,

There are two issues that are preventing bokeh server from running your script. The first is that __name__ will not equal '__main__' when the script is executed using bokeh server. The second issue is that packing your script inside a function call will prevent bokeh server from finding what it needs to run your code. If you move the body of your code out of main() and remove the __name__ == '__main__' condition, it should work as intended. Here’s an example of what I mean:

import pandas as pd
try    :
# This import only works in 3.X
    from io import StringIO
except ImportError:
# attempt to cover 2.X use
    from StringIO import StringIO
from bokeh.layouts import row, widgetbox
from bokeh.models import Select
from bokeh.palettes import Spectral5
from bokeh.plotting import curdoc, figure
# trimmed down example data set
data = """
Filename,Date,EntityType,EntityValue
1101163308494.txt,5/13/2004,ORG, Date
1101163308494.txt,5/13/2004,ORG, Alderwood High School
1101163308494.txt,5/13/2004,PER, Stacey Gorski
"""

# mostly unchanged code, now outside of main()
df = pd.read_csv(StringIO(data))
df['Filename'] = df['Filename'].astype(str)
df['Date'] = df['Date'].astype(str)
df['EntityType'] = df['EntityType'].astype(str)
df['EntityValue'] = df['EntityValue'
].astype(str)
columns = sorted(df.columns)
discrete = [x for x in columns if df[x].dtype == object]
continuous = [x for x in columns if x not in discrete]
quantileable = [x for x in continuous if len(df[x].unique()) > 20
]
def create_figure():
    xs = df[x.value].values
ys = df[y.value].values
x_title = x.value.title()
y_title = y.value.title()
kw = dict()
if x.value in discrete:
kw['x_range'    ] = sorted(set(xs))
if y.value in discrete:
kw['y_range'    ] = sorted(set(ys))
kw['title'] = "%s vs %s" % (x_title, y_title)
p = figure(plot_height=400, plot_width=400, tools='pan,box_zoom,reset'    , **kw)
p.xaxis.axis_label = x_title
p.yaxis.axis_label = y_title
p.circle(x=xs, y=ys, line_color="white", alpha=0.6, hover_color='white', hover_alpha=0.5    )
return p
def update(attr, old, new):
    layout.children[1
] = create_figure()
x = Select(title='X-Axis', value='Date', options=columns)
y = Select(title='Y-Axis', value='EntityValue', options=columns)
x.on_change('value', update)
y.on_change('value'
, update)
controls = widgetbox([x, y], width=200
)
layout = row(controls, create_figure())
curdoc().add_root(layout)
curdoc().title = "Crossfilter New"

# __name__ == '__main__' condition removed

···

On Friday, June 23, 2017 at 1:25:07 PM UTC-7, Lopamudra Pal wrote:

I implemented the crossfilter graph with our data. Issue faced - When outputting the result with bokeh.io.show method, I get the desired graph but with no interactions possible. However if I run the script as a bokeh application using “bokeh serve script.py --show”, I get a blank webpage. I tried figuring out the issue for quite a while but still cannot identify what might possibly be the problem. The script works fine with the bokeh team’s sample data though. Any suggestions would really be helpful.

Note:- Our data does not have any integer or float values. Hence I have commented out the continuous and quantileable parts from the original example code.

Tyler I just want to say that I appreciate your taking the time to share your experience and help out here!

Thanks,

Bryan

···

On Jun 29, 2017, at 13:44, Tyler Nickerson <[email protected]> wrote:

Hello,

There are two issues that are preventing bokeh server from running your script. The first is that __name__ will not equal '__main__' when the script is executed using bokeh server. The second issue is that packing your script inside a function call will prevent bokeh server from finding what it needs to run your code. If you move the body of your code out of main() and remove the __name__ == '__main__' condition, it should work as intended. Here’s an example of what I mean:

import pandas as
pd

try
:
    
# This import only works in 3.X

from io import
StringIO

except
ImportError:
    
# attempt to cover 2.X use

from StringIO import
StringIO

from bokeh.layouts import
row, widgetbox

from bokeh.models import
Select

from bokeh.palettes import
Spectral5

from bokeh.plotting import
curdoc, figure

# trimmed down example data set

data =
"""
Filename,Date,EntityType,EntityValue
1101163308494.txt,5/13/2004,ORG, Date
1101163308494.txt,5/13/2004,ORG, Alderwood High School
1101163308494.txt,5/13/2004,PER, Stacey Gorski
"""

# mostly unchanged code, now outside of main()

df = pd.read_csv(StringIO(data))
df[
'Filename'] = df['Filename'
].astype(str)
df[
'Date'] = df['Date'
].astype(str)
df[
'EntityType'] = df['EntityType'
].astype(str)
df[
'EntityValue'] = df['EntityValue'
].astype(str)

columns = sorted(df.columns)
discrete = [x
for x in columns if
df.dtype == object]
continuous = [x
for x in columns if x not in
discrete]
quantileable = [x
for x in continuous if len(df.unique()) > 20
]

def create_figure():

    xs = df[x.value].values
    ys = df[y.value].values
    x_title = x.value.title()
    y_title = y.value.title()

    kw = dict()
    
if x.value in
discrete:
        kw[
'x_range'
] = sorted(set(xs))
    
if y.value in
discrete:
        kw[
'y_range'
] = sorted(set(ys))
    kw[
'title'] = "%s vs %s"
% (x_title, y_title)

    p = figure(plot_height=
400, plot_width=400, tools='pan,box_zoom,reset'
, **kw)
    p.xaxis.axis_label = x_title
    p.yaxis.axis_label = y_title
    p.circle(x=xs, y=ys, line_color=
"white", alpha=0.6, hover_color='white', hover_alpha=0.5
)
    
return
p

def update(attr, old, new):

    layout.children[
1
] = create_figure()

x = Select(title=
'X-Axis', value='Date'
, options=columns)
y = Select(title=
'Y-Axis', value='EntityValue'
, options=columns)
x.on_change(
'value'
, update)
y.on_change(
'value'
, update)

controls = widgetbox([x, y], width=
200
)
layout = row(controls, create_figure())

curdoc().add_root(layout)
curdoc().title =
"Crossfilter New"

# __name__ == '__main__' condition removed
On Friday, June 23, 2017 at 1:25:07 PM UTC-7, Lopamudra Pal wrote:

I implemented the crossfilter graph with our data. Issue faced - When outputting the result with bokeh.io.show method, I get the desired graph but with no interactions possible. However if I run the script as a bokeh application using "bokeh serve script.py --show", I get a blank webpage. I tried figuring out the issue for quite a while but still cannot identify what might possibly be the problem. The script works fine with the bokeh team's sample data though. Any suggestions would really be helpful.

Note:- Our data does not have any integer or float values. Hence I have commented out the continuous and quantileable parts from the original example code.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6d845ecc-1479-4442-be65-396f09e2427e%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.