R. S. Doiel, rsdoiel@caltech.edu
Caltech Library, Digital Library Development
2025-06-12
Welcome everyone. This is a talk and hands on workshop.
An approach to building web applications using Dataset and Web Components
Follow along at https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation1.html
Download the presentation zip file at https://github.com/caltechlibrary/t2t3_dataset_web_apps/releases
We can start our first iteration of our application once you have these available.
GOAL: A simple web application that lets us curate a list of recipes.
We’re going start from the back end and spend most of our time on the front end.
recipes.ds
collectionrecipes.ds
collectionWe use the dataset
command line program to initialize a
dataset collection.
dataset init recipes.ds
(Linux, macOS and Windows)
Download sample data file recipes.jsonl (see: https://github.com/caltechlibrary/t2t3_dataset_web_apps/blob/main/recipes.jsonl)
cat recipes.jsonl | dataset load recipes.ds
On Windows:
Get-Content recipes.jsonl | dataset load recipes.ds
dataset keys recipes.ds
dataset read recipes.ds frybread
$ dataset keys recipes.ds
blondies
brownies
cafe-con-leche
frybread
poi
waffles
$ dataset read recipes.ds frybread
{
"ingredients": "backing powder,2 tsp\r\nflour,2 cups\r\nhot water,2/3 cups\r\nsalt,1 tsp salt\r\nshortening,2 Tbsp\r\n",
"key": "frybread",
"name": "Fry Bread",
"procedure": "1. Combine flour, baking powder, and salt in a bowl.\r\n2. Use a pastry blender (or two butter knives) to cut the shortening into the flour.\r\n3. Add the hot water, and mix until the water is incorporated and you get a dough.\r\n4. Turn out the dough on a lightly floured board. Knead the dough until it is soft and smooth.\r\n5. Wrap the dough in plastic, and let the dough rest for 30 minutes.\r\n6. Divide the dough into 6 pieces, roll each into a ball, and roll each into a flat disk with a rolling pin.\r\n7. Brush one side of each disk with melted margarine and place on a barbecue over a 3 Mississippi fire.\r\n8. Brush the opposing side of the bread with margarine and flip the bread on the barbecue.\r\n9. Cook until both sides are golden brown. Serve hot.\r\n\r\n- You can substitute either 1/4 cup plain yogurt, or a 1/4 cup soured milk as a leavening agent\r\ninstead of baking powder. If you do, add 2 hours to the rest time for the dough, and leave\r\nthe dough somewhere warm. You can optionally include the baking powder as well to get a\r\nvery puffy version of frybread. If using yogurt or soured milk for leavening, use 1\2 cup\r\ninstead of 1/3 cup water.\r\n- You can use mayonnaise in place of shortening for a crispy, crunchier texture.\r\n- You can also fry the dough in hot oil over a stovetop. The dough cooks rapidly and will brown\r\nin about 12 seconds and must be turned over to allow the opposite side to brown, then be removed\r\nfrom the oil and placed sideways into a colander or large bowl lined with paper towels to allow\r\nthe oil to drain off the finished product\r\n\r\nurl: https://en.wikibooks.org/wiki/Cookbook:Fry_Bread_I\r\n"
}
mkdir htdocs
mkdir htdocs/modules
mkdir htdocs/css
datasetd
provides a turn key web service defined by a
simple YAML file. It can host one or more dataset collections. It
provides a static file service as well as a JSON API for each
collection.
Create the file recipes_api.yaml (see: https://github.com/caltechlibrary/t2t3_dataset_web_apps/blob/main/recipes_api.yaml).
#!/usr/bin/env -S datasetd -debug
host: localhost:8001
htdocs: htdocs
collections:
- dataset: recipes.ds
keys: true
create: true
# When we successfully create (or update via a POST) an object display it
create_success: http://localhost:8001/display_recipe.html
# When we fail go back to the current page.
create_error: http://localhost:8001/edit_recipe.html
read: true
update: true
delete: true
query:
list_recipes: |
select src
from recipes
order by src->>'name'
Starting the web service.
datasetd -debug recipes_api.yaml
datasetd -debug recipes_api.yaml
?(on macOS, Linux or Window’s WSL)
chmod 775 recipes_api.yaml
Now you can shorten start up to
./recipes_api.yaml
The web service is running but haven’t populated the htdocs directory.
What do you see when you go to http://localhost:8001/?
input
element
textarea
or for display a
table
.
textarea
element
We’ll need a submit button to save a new or edited recipe.
We’ll create four modules, one specific to each HTML page and one utility module
In a terminal run our startup command
datasetd -debug recipes_api.yaml
Let’s take a short break then we’ll comeback and iterate.
I’m available for questions.
What we are doing next
recipes2.ds
recipes_api2.yaml
htdocs2
dataset init recipes2.ds
cp recipes_api.yaml recipes_api2.yaml
cp -vR htdocs htdocs2
On Windows:
dataset init recipes2.ds
copy recipes_api.yaml recipes_api2.yaml
copy -Recurse htdocs htdocs2
(NOTE: The first line should look familiar, the others are just time savers)
htdocs
referencerecipes2.ds
datasetd recipes_api2.yaml
(NOTE: note the “d” at the end of “datasetd”)
utils.js
module includes a saveRecipe
functionAdd the following at the bottom of the page before the
</body>
.
datasetd -debug recipes_api2.yaml
Test using your web browser.
https://github.com/caltechlibrary/CL-web-components/releases
htdocs2/modules/
.unzip $HOME/Downloads/cl-web-components-0.0.6.zip *.js
mv -v *.js htdocs2/models/
htdocs2/edit_recipe.html
<csv-textarea>
See: https://github.com/caltechlibrary/t2t3_dataset_web_apps/blob/main/htdocs2/edit_recipe.html
<csv-textarea>
?<csv-textarea>
<csv-textarea>
column-headings="Ingredients,Units"
debug="true"
Start up our web service
dataset recipes_api2.yaml
utils.js
CSVTextarea has the ability to be updated from CSV text. Let’s do that.
In edit_recipe.js
you need to find this.
And replace it with something like this.