Public
Edited
Feb 24
Paused
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// videos joined with any extras
ytVids = T.tidy(videos, T.leftJoin(extras, { by: "id" }))
Insert cell
videos = dataSource.sql`select * from video`
Insert cell
// extra notes for a vid
extras = {
const sqlData = await dataSource.sql`select * from extras`;
const combined = sqlData.reduce((acc, obj) => {
const { videoId, ...rest } = obj;
acc[videoId] = acc[videoId] || [];
acc[videoId].push({ ...rest });
return acc;
}, {});
const tidyCombined = Object.keys(combined).map((d) => ({
id: +d,
extras: combined[d]
}));
return tidyCombined
}
Insert cell
// make extras into bulleted list
extraList = {
const extras = selectedVid.extras
return extras
? extras.map(d => {
const blurb = d.blurb
? ": " + d.blurb
: ""
return `- [${d.linkText}](${d.linkUrl})${blurb}`
}).join("\n")
: ""
}
Insert cell
Insert cell
// import data from github
dataSource = K.githubApi("https://github.com/cookwcode/data/blob/yts-v1/yts--smile-youtube/ytVids.db")
.then(SQLiteDatabaseClient.open)
Insert cell
// pick the video from dataset: random or most recent by date...or selection
selectedVid = {
button;
// if table selection, show that
if (table) return ytVids.filter(d => d.id == table.id)[0]
// get random index
const shuffleIndex = Math.floor(Math.random() * ytVids.length)
return sortType == radioOptions[0]
? ytVids.sort((a,b) => new Date(b.date) - new Date(a.date))[0]
: ytVids[shuffleIndex]
}
Insert cell
/**
* Take YoutTube link and get back the embed string
*/
function getYTEmbedString(link) {
// split up link, get only relevant bit
const separated = link.split("/")
const cleanedSlug = separated.slice(-1)[0].match(/^[a-zA-Z0-9-_]+/)[0]
return cleanedSlug
}
Insert cell
// choices for vid selection
radioOptions = ["Most Recent Vid", "Random Vid"]
Insert cell
function linkNewTab(
text = "Example",
link = "https://www.example.com/"
) {
return htl.html`<a href="${link}" target="_blank">${text}</a>`;
}
Insert cell
// tidyjs
T = K.tools.tidyjs
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more