Skip to content

Instantly share code, notes, and snippets.

@hageldave
Last active October 14, 2025 13:04
Show Gist options
  • Save hageldave/5ebac124cc62e383547a83cb3dbf0b59 to your computer and use it in GitHub Desktop.
Save hageldave/5ebac124cc62e383547a83cb3dbf0b59 to your computer and use it in GitHub Desktop.
A simple bokeh server example
from typing import Callable
from bokeh.server.server import Server
from bokeh.document import Document
from bokeh.models import Div, ColumnDataSource
from bokeh.plotting import figure
import pandas as pd
import sklearn.datasets as toy_data
def create_application(doc):
# website titles
doc.title = "Bokeh Skeleton"
doc.add_root(Div(text="<b>Bokeh Skeleton</b>"))
# data
iris = toy_data.load_iris()
df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
df['label'] = iris.target
df['label_name'] = [iris.target_names[i] for i in iris.target]
cds = ColumnDataSource(data=df)
# visualization
plot = figure(width=300, height=300)
col_x = iris.feature_names[0]
col_y = iris.feature_names[1]
print(f"plotting {col_x} against {col_y}")
renderer = plot.circle(x=col_x, y=col_y, source=cds, radius=2, radius_units="screen")
doc.add_root(plot)
def start_server(setup_callable: Callable[[Document], None]):
server = Server(setup_callable)
# start timers and services and immediately return
server.start()
server.io_loop.add_callback(server.show, "/")
server.io_loop.start()
if __name__ == '__main__':
start_server(create_application)
@hageldave
Copy link
Author

requirements (pip install):

bokeh
pandas
scikit-learn

run in IDE or via CLI

python bokeh_server_skeleton.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment