THINK FIRST·CODE LATER

← All labs

The Bokeh 3 sales dashboard, done right

Problem

Rebuild the Bokeh case study with the current API. Input: a CSV Date,Region,Sales.

  • Two ColumnDataSources: all rows, and the rows of the first region (sorted names) that are shown.
  • figure(...) with width=700, height=400, datetime x axis, tools pan,box_zoom,reset,save, title Monthly Sales Trend for <region>; a line and a scatter(size=6) on the shown source; a HoverTool on the line with tooltips Date @Date{%F} and Sales @Sales{0,0} and a datetime formatter.
  • A Select widget (title Select Region:) whose js_on_change("value", CustomJS(...)) callback filters the full source into the shown source and updates the title, so the page works as a standalone HTML file.

Print: glyphs: Line, Scatter, tools: PanTool, BoxZoomTool, ResetTool, SaveTool, HoverTool, select: options [...], value East, size: 700x400, title: Monthly Sales Trend for East, source columns: Date, Region, Sales (without index), rows shown initially: 3, callbacks on select: CustomJS.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

v8-3-data-1.csv

Date,Region,Sales
2024-01-01,North,5000
2024-01-01,South,3000
2024-01-01,East,4000
2024-01-01,West,3500
2024-02-01,North,5200
2024-02-01,South,3100
2024-02-01,East,4200
2024-02-01,West,3700
2024-03-01,North,5100
2024-03-01,South,3300
2024-03-01,East,4600
2024-03-01,West,3600
What your program must print for v8-3-data-1.csv
glyphs: Line, Scatter
tools: PanTool, BoxZoomTool, ResetTool, SaveTool, HoverTool
select: options ['East', 'North', 'South', 'West'], value East
size: 700x400, title: Monthly Sales Trend for East
source columns: Date, Region, Sales
rows shown initially: 3
callbacks on select: CustomJS

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), in the folder that holds both files:

python my_lab.py < v8-3-data-1.csv

Windows PowerShell (the default terminal of VS Code on Windows) does not understand <:

Get-Content v8-3-data-1.csv | python my_lab.py

PyCharm: Run → Edit Configurations → tick Redirect input from and choose the file.

Jupyter: put this at the top of the cell that holds your program:

import sys
sys.stdin = open("v8-3-data-1.csv", encoding="utf-8")

Write it here, in Jupyter or in your IDE, then paste it. Run it on the sample input yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.