Hi, I’m fairly new to bokeh and I can see there are a lot of posts on this topic, but I’ve been googling this all weekend, without finding a solution, so I’ll try here:
I have some trouble implementing a RangeSlider and Select widget. They show up in the plot with their initial values, but nothing happens to the plot when click on them.
I can only assume this has to do with my callback methods, but I can’t see how they differ from the callback function in e.g. bokeh/main.py at branch-3.0 · bokeh/bokeh · GitHub (the slider_update() - method). Here’s my bokeh script:
import pandas as pd
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource, Slider, Select
from bokeh.plotting import figure
from bokeh.models.widgets import RangeSlider
from bokeh.layouts import column, row
df = pd.read_csv(“temperature.csv”, header=0)
source = ColumnDataSource(df)
months = df.columns.values.tolist()
plot = figure(plot_width=1000, plot_height=600)
plot.line(x=“Year”, y=“January”, source=source)
menu = Select(options=months, value=“June”, title=“Month”)
start, end = df[“Year”].iloc[0], df[“Year”].iloc[-1]
slider = RangeSlider(start=start, end=end, value=(start, end), step=1, title=“Year”)
def select_callback(attr, old, new):
source.data = df[menu.value]
menu.on_change(‘value’, select_callback)
def slider_callback(attr, old, new):
source.data = df.loc[slider.value[0] : slider.value[1], :]
slider.on_change(‘value’, slider_callback)
layout = column(plot, row(menu, slider))
curdoc().add_root(layout)
``
I am trying to show this plot in the browser using Flask, with the app:
from flask import Flask, render_template
from bokeh.embed import autoload_server
app = Flask(name)
@app.route("/")
def index():
script = autoload_server(None, url=“http://localhost:5006/plot_script”)
return render_template(“temp.html”)
if name==“main”:
app.run(port=5000, debug=True)
``
Both the Flask app and running with simply bokeh serve --show plot_script.py yield the same unresponsive graph.
The csv file has no issues, but there might be something wrong with the html template. Does anyone have any idea as to how to generate a template from the plot_script.py program? (See attchments)
temperature.csv (24.7 KB)
temp.html (36.5 KB)