Published
Edited
Dec 2, 2021
Importers
24 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db = DatasetteClient("https://ds.agarcia.dev/congress/congress-members")
Insert cell
Insert cell
db`
SELECT
bioguide,
first_name,
last_name
FROM members
WHERE first_name LIKE "ALEX%"
LIMIT 25;`
Insert cell
Insert cell
info = db.info()
Insert cell
Insert cell
viewof millennialMembers = db.table`
SELECT bioguide,
first_name,
last_name,
CAST(strftime('%Y', DATE(birthday)) AS INTEGER) AS birth_year
FROM members
WHERE
birth_year >= 1981
AND birth_year <= 1996
ORDER BY birth_year DESC`
Insert cell
millennialMembers
Insert cell
Insert cell
viewof party = html`<select>
<option>Democrat</option>
<option>Republican</option>
<option>Independent</option>`
Insert cell
db.table`
SELECT
full_name,
terms.type,
terms.state,
terms.party,
terms.start,
terms.end
FROM members
LEFT JOIN terms ON terms.member = members.bioguide
GROUP BY bioguide
HAVING
date(max(terms.end)) > date("now")
and terms.type = "sen"
and terms.party = ${party}
ORDER BY state ASC`
Insert cell
Insert cell
Insert cell
// Note: There are more than these two genders! But in this dataset of members of US Congress, there are only "M" and "F" values in the gender field (so far!)
viewof gender = html`<select>
<option>M</option>
<option selected>F</option>`
Insert cell
beforeDate = '1900-01-01'
Insert cell
// Try removing the "dry" to see the results of the query!
db.dry`SELECT * FROM members WHERE gender = ${gender} AND birthday < ${beforeDate}`
Insert cell
Insert cell
viewof selectedMembers = html`<select multiple>
<option selected>alexandria</option>
<option selected>ilhan</option>
<option>nancy</option>
<option>mitt</option>
<option>karen</option>`
Insert cell
db.table`
SELECT *
FROM members
WHERE LOWER(first_name) in
${selectedMembers}`
Insert cell
Insert cell
db.table`select from members;`
Insert cell
db.table`select not_exist from members;`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chartData = Object.assign(
repsGenerations.map(d => ({ ...d, date: new Date(d.date) })),
{ columns: repsGenerations.columns }
)
Insert cell
Insert cell
color = d3
.scaleOrdinal()
.domain(chartData.columns.slice(1))
.range(['#ccc', '#2b6455', '#53887b', '#ddc172', '#c79a27'])
Insert cell
Insert cell
import { d3, chart, swatches } with {
chartData as data,
color
} from '@d3/stacked-area-chart'
Insert cell
swatches({ color })
Insert cell
chart
Insert cell
Insert cell
Insert cell
import { DatasetteClient } from '@asg017/datasette-client-core'
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more