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