Published
Edited
Dec 7, 2020
4 stars
Insert cell
Insert cell
import { DatasetteClient } from '@asg017/datasette-client-core'
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
faviconDB = DatasetteClient(
'https://datasette-render-images-demo.datasette.io/favicons'
)
Insert cell
Insert cell
Insert cell
Insert cell
faviconDBTable = faviconDB.table.options({
renderCell: (value, column) => {
if (!column.endsWith('_png')) return;
const url = encodedBase64ToUrl(value.encoded, 'image/png', invalidation);
return html`<image src=${url}>`;
}
})
Insert cell
Insert cell
viewof mozillaIcons = faviconDBTable`
SELECT
data as image_png,
icon_url
FROM favicons
WHERE icon_url LIKE "%mozilla%"`
Insert cell
mozillaIcons
Insert cell
faviconDBTable`SELECT data as image_png, icon_url FROM favicons WHERE icon_url LIKE "data%"`
Insert cell
Insert cell
Insert cell
videosDB = DatasetteClient('https://ds.agarcia.dev/pronunciationmanual/videos')
Insert cell
videosDBTable = videosDB.table.options({
renderCell: (value, column) => {
if (!column.endsWith('_mp4')) return;
const url = encodedBase64ToUrl(value.encoded, 'video/mp4', invalidation);
return html`<video src=${url} controls width=400>`;
}
})
Insert cell
videosDBTable`SELECT name, video as video_mp4 FROM videos`
Insert cell
Insert cell
Insert cell
Inspector = (await require('@observablehq/inspector')).Inspector
Insert cell
// The Observable notebook Inspector wasn't really meant to be used this way (it's usually used alongside the Observable runtime), but hey, it works!
inspect = value => {
const i = new Inspector(html`<div>`);
i.fulfilled(value);
return i._node;
}
Insert cell
Insert cell
jsonDB = DatasetteClient('https://datasette-json-html.datasette.io/demo')
Insert cell
Insert cell
jsonDBTable = jsonDB.table.options({
renderCell: (value, column) =>
column.endsWith('_json') && inspect(JSON.parse(value))
})
Insert cell
Insert cell
jsonDBTable`
select
rowid,
package,
url,
json_object('package', package, 'url', url) as pkg_json
from packages`
Insert cell
jsonDBTable`select
json_array(1,2,3,4,5) as arrays_json
union all
select json_array("spongebob", "fairly", "odd", "parents")`
Insert cell
Insert cell
trumpMentionsDB = DatasetteClient(
'https://twitter-mentions-trump.herokuapp.com/trump_mentions'
)
Insert cell
import { tweet } from '@mbostock/tweet'
Insert cell
trumpMentionsDBRenderTweetsTable = trumpMentionsDB.table.options({
renderCell: (value, column) =>
column.endsWith('_tweet') &&
html`<div style="max-width: 200px;">${tweet(value)}`
})
Insert cell
trumpMentionsDBRenderTweetsTable`
SELECT
id as trump_tweet,
account_type,
state,
party,
mention
FROM mentions
WHERE mention = "BetsyDeVos"`
Insert cell
trumpMentionsDBRenderTweetsTable`select id as trump_tweet, account_type, state, party, mention from mentions where mention like "%Ivanka%" limit 1`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
powerPlantsDB = {
await visibility();
return DatasetteClient(
'https://global-power-plants.datasettes.com/global-power-plants'
);
}
Insert cell
Insert cell
Insert cell
Insert cell
powerPlantsDBClusterMap`select * from [global-power-plants] where country_long = "Vietnam"`
Insert cell
viewof mexPlants = powerPlantsDBClusterMap`select * from [global-power-plants] where country_long = "Mexico" `
Insert cell
mexPlants
Insert cell
Insert cell
viewof country = select({
options: await powerPlantsDB`select distinct country_long as label, country_long as value from [global-power-plants]`,
value: "Canada"
})
Insert cell
viewof fuel_type = select({
options: await powerPlantsDB`select distinct primary_fuel as label, primary_fuel as value from [global-power-plants] where country_long = ${country}`
})
Insert cell
powerPlantsDBClusterMap`select * from [global-power-plants] where primary_fuel = ${fuel_type} and country_long = ${country}`
Insert cell
Insert cell
githubDB = {
// `visibility` is an builtin cell in Observable, added here to keep initial page loads fast
await visibility();
return DatasetteClient('https://github-to-sqlite.dogsheep.net/github');
}
Insert cell
import { importCell } from '@mbostock/dataflow'
Insert cell
viewof repo = select({
options: await githubDB`select name as label, name as value from repos inner join commits on commits.repo = repos.id group by repos.name`,
value: "datasette"
})
Insert cell
githubDB.render((rows, columns) =>
importCell('chart', '@d3/calendar-view', {
data: rows.map(d => ({ ...d, date: new Date(d.date) }))
})
)`
SELECT
strftime("%Y-%m-%d", committer_date) as date,
count(*) as value
FROM commits
LEFT JOIN repos ON repos.id = commits.repo
WHERE repos.name = ${repo}
GROUP BY date`
Insert cell
Insert cell
import { select } from '@jashkenas/inputs'
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