Published
Edited
Sep 26, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`Here is some Markdown. Edit me! You can add...
# Headers of
### different sizes,
* bullet
* points

\`fixed width font\`

1. Ordered
2. Lists,

and more. For reference, here is a [guide to formatting using the Markdown syntax](https://observablehq.com/@jaynel/markdown-summary).`
Insert cell
or using the new Markdown mode of Observable:
Insert cell
Here is some Markdown. Edit me! You can add...
# Headers of
### different sizes,
* bullet
* points

\`fixed width font\`

1. Ordered
2. Lists,

and more. For reference, here is a [guide to formatting using the Markdown syntax](https://observablehq.com/@jaynel/markdown-summary).
Insert cell
Insert cell
html`<h4>Here is some HTML</h4>`
Insert cell
<h4>Here is some HTML</h4>
Insert cell
{
const course = "CSE442";
const message = "Welcome to " + course;
return message;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
currentWeek = 1
Insert cell
"There are " + (10 - currentWeek) + " weeks left in the quarter"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
442 // a number
Insert cell
Insert cell
true // a boolean
Insert cell
isNaN(442) // you may use isNaN(a) to check if a is Not-A-Number
Insert cell
(1 + Math.sqrt(5)) / 2 // you can also do math
Insert cell
Math.random() // or generate 'random' numbers
Insert cell
2 < 1 // you can compare things
Insert cell
"A" < "a" // including string comparisons
Insert cell
2 + 2 === 4 // more comparison
Insert cell
2 + 2 !== "4" // and more
Insert cell
Insert cell
2 + 2 == "4" // double equals
Insert cell
2 + 2 === "4" // triple equals
Insert cell
Insert cell
Insert cell
date = new Date()
Insert cell
Insert cell
Insert cell
Insert cell
function addMe(a, b) { // function signature: name and input arguments
return a + b; // function body, with return statement for output
}
Insert cell
Insert cell
addMe(2, 2)
Insert cell
addMe('data', ' visualization')
Insert cell
addMe('💕', 'U', '😍') // sorry heart-eyes, extra arguments are ignored
Insert cell
Insert cell
addMe('1') // something from nothing
Insert cell
Insert cell
addMe2 = (a, b) => a + b
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
arr1 = [1, 2, 3, 'hi'] // you can initialize an array like this
Insert cell
{
arr1.push('Husky'); // you can push elements to array, this updates the array content
return arr1;
}
Insert cell
Insert cell
Insert cell
arr1.map(d => d * 2)
Insert cell
Insert cell
result = arr1.filter(d => !isNaN(d)).map(d => d * 2) // keep valid numbers only, then double them
Insert cell
result.slice().sort() // the default sort method is ascending
Insert cell
result
.slice() // you can first make a copy of an array, so we don't overwrite earlier values
.sort((a, b) => b - a) // you can define a custom sort comparator; here we sort numbers in descending order
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
object['key'] = 'new Value'
Insert cell
object['newKey'] = 'new value'
Insert cell
Object.keys(object) // return an array of property key strings
Insert cell
Object.values(object) // return an array of property values
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
csvText = FileAttachment("sample1@1.csv").text() // loading a text file attached in Observable
Insert cell
dataCSV = d3.csvParse(csvText) // if we have the text loaded already, we can use d3.csvParse
Insert cell
csvURL = FileAttachment("sample1@1.csv").url() // you can get the url of a file you attached to Observable with .url()
Insert cell
dataCSV2 = d3.csv(csvURL) // if we have a URL to a CSV, we can use d3.csv to both load and parse
Insert cell
Insert cell
auto = d3.csv(csvURL, d3.autoType) // can handle numbers and booleans, but not all date formats
Insert cell
manual = d3.csv(csvURL, ({Name, Job, date}) => ({Name: Name, Job: Job, 'OH Date': new Date(date)}))
Insert cell
datee = manual[1]['OH Date'].getDay()
Insert cell
Insert cell
Insert cell
FileAttachment("sample1.json").text() // here's what JSON data looks like as text
Insert cell
dataJSON = FileAttachment("sample1.json").json() // load and parse JSON from a file attached in Observable
Insert cell
json_url = FileAttachment("sample1.json").url() // we can also get a URL for a file attachment
Insert cell
Insert cell
Insert cell
strJson = JSON.stringify(dataJSON)
Insert cell
JSON.parse(strJson)
Insert cell
Insert cell
Insert cell
Insert cell
// your code goes here
// uncomment cell below to see the solution
Insert cell
Insert cell
Insert cell
// your code goes here
// uncomment cell below to see the solution
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
cars = (await require('vega-datasets@1'))['cars.json']()
Insert cell
Insert cell
printTable(cars.slice(0,10))
Insert cell
Insert cell
Insert cell
cars_table = aq.from(cars).view()
Insert cell
Insert cell
// to be filled -- filter only USA.
// op.upper(): Returns the string value converted to upper case.
// op.includes(array, value[, index]): Determines whether an array includes a certain value among its entries, returning true or false as appropriate.
Insert cell
Insert cell
// to be filled -- filter and get the highest mpg in the USA.
Insert cell
Insert cell
// to be filled -- filter for cars only made from USA, sort in decending order, and select a subset of collumn to show for 5 rows only.

Insert cell
Insert cell
Insert cell
Insert cell
// to be filled -- find answer for each region
Insert cell
Insert cell
// to be filled -- change the unit for the weights
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