Boker server: Widgets not working using bokeh server in Ubuntu but working fine in windows

Hi, I am trying to make a simple bokeh app using the bokeh server in which using a button widget I want to show a plot. The code is saved as script.py and is given as follows.

import pandas as pd
import numpy as np
from bokeh.plotting import figure
from bokeh.models import Button, ColumnDataSource
from bokeh.layouts import column
from bokeh.io import curdoc

my_dict = {'Col1' : np.arange(0, 100, 10),
           'Col2' : np.arange(0,1000,100)}

my_df = pd.DataFrame.from_dict(my_dict)

def plot(df):
    
    source = ColumnDataSource(data=df)
    tools = ['xpan', 'xwheel_zoom', 'xbox_zoom', 'xzoom_in',
              'yzoom_out', 'undo', 'reset']
    
    p = figure(width=768, height=360,
                tools=tools, toolbar_location="right",
                title='Plot')
    
    for i in df.columns:
        p.line(x='index', y=i, width=2, source=source, legend_label=i)
        
    p.legend.click_policy="hide"
    
    return p

p = plot(my_df)

button = Button(label="Show plot on click", button_type="success")

def bc(p=p, button=button):
    curdoc().clear()
    curdoc().add_root(column(button,p))
    
button.on_click(bc)
curdoc().add_root(button)

I run this basic app using the command: bokeh serve --show script.py. This app works fine when run on windows and using the button widget it shows the plot.

However when I run the app on ubuntu with the command python3 -m bokeh serve script.py --port 5010 --allow-websocket-origin="*" the button widget does not work, nothing happens on the click, the plot does not appear.

Your guidance is appreciated.
Thank you :slight_smile:

@Bryan @pavithraes

@Omi The code does not work for me, so I guess I would regard it as a bug (please file a GitHub Issue with details). However I would also say completely clearing curdoc is uncommon usage. I’d suggest instead adding some top level layout container (e.g. row or column) once up front, and then replacing the contents inside the container, and see if that works better.

1 Like

Hi @Bryan, I did as you suggested and it worked. Possibly it wasn’t a bug but an incorrect usage of curdoc() in the app which worked on the bokeh server in windows but not on Ubuntu. The following code works smoothly. Thank you for your support. :slight_smile:

import pandas as pd
import numpy as np
from bokeh.plotting import figure
from bokeh.models import Button, ColumnDataSource
from bokeh.layouts import layout
from bokeh.io import curdoc

my_dict = {'Col1' : np.arange(0, 100, 10),
           'Col2' : np.arange(0,1000,100)}
my_df = pd.DataFrame.from_dict(my_dict)


def plot(df):
    source = ColumnDataSource(data=df)
    tools = ['xpan', 'xwheel_zoom', 'xbox_zoom', 'xzoom_in',
             'yzoom_out', 'undo', 'reset']
    p = figure(width=768, height=360,
               tools=tools, toolbar_location="right",
               title='Plot')
    for i in df.columns:
        p.line(x='index', y=i, width=2, source=source, legend_label=i)    
    p.legend.click_policy="hide"
    return p

p = plot(my_df)
button = Button(label="Show plot on click", button_type="success")
lt = layout(children=[button]) 

def bc():
    lt.children[0] = p  
   
button.on_click(bc)
curdoc().add_root(lt)
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.