Public
Edited
Dec 8, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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 table
// 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
radioOptions = ["Most Recent Vid", "Random Vid"]
Insert cell
Insert cell
Insert cell
Insert cell
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