Last active
January 29, 2025 10:35
-
-
Save hageldave/5ebac124cc62e383547a83cb3dbf0b59 to your computer and use it in GitHub Desktop.
A simple bokeh server example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bokeh.server.server import Server | |
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(): | |
server = Server(create_application) | |
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requirements (pip install):
run in IDE or via CLI