Platform
Solutions
Resources
Pricing
Sign in
Sign up
rlluo1
Workspace
Fork
Published
Class_materials_11.454
By
rlluo1
Edited
Mar 13, 2019
Class_materials_11.454
Bio Data Analysis
Week 12 - Interaction and Animation: D3 Transitions, Behaviors, and Brushing
Week 11 - Intro to D3.js: Mapping Data with D3
Week 10b - Intro to D3.js: Making a Chart
Week 10 - Intro to D3.js: Making a Chart
Parsing API Responses
Week 5a - Web APIs
Week 3a - Data Management
Week 3 - Data Management with Zebras
Week 2b - Advanced Javascript
Week 2a - Introduction to Javascript Part2
Week 1b - Introduction to Javascript
Week 1a - Introduction to HTML and Javascript - Rachel's notes
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
resolveAfter2Seconds
=
function
(
x
)
{
return
new
Promise
(
resolve
=>
{
setTimeout
(
(
)
=>
{
resolve
(
x
)
}
,
2000
)
}
)
}
Insert cell
f1
=
async
function
(
number
)
{
var
x
=
await
resolveAfter2Seconds
(
number
)
;
console
.
log
(
x
)
return
x
}
Insert cell
f1
(
5
)
Insert cell
Insert cell
Insert cell
Insert cell
vegalite
=
require
(
"@observablehq/vega-lite@0.1"
)
Insert cell
z
=
require
(
'https://bundle.run/zebras@0.0.11'
)
Insert cell
Insert cell
// Load a file locally
viewof
text
=
html
`<input type=file * ">`
Insert cell
tweetsStrings
=
Files
.
text
(
text
)
Insert cell
tweetsDF
=
Object
.
values
(
JSON
.
parse
(
tweetsStrings
)
)
Insert cell
Insert cell
count
=
{
let
countArray
=
[
]
let
groupedLocations
=
z
.
groupBy
(
x
=>
x
.
location
,
tweetsDF
)
for
(
const
key
of
Object
.
keys
(
groupedLocations
)
)
{
countArray
.
push
(
{
location
:
key
,
count
:
groupedLocations
[
key
]
.
length
}
)
}
return
countArray
}
Insert cell
Insert cell
countSorted
=
z
.
sortByCol
(
'count'
,
'des'
,
count
)
Insert cell
vegalite
(
{
data
:
{
values
:
countSorted
.
slice
(
0
,
40
)
}
,
mark
:
"bar"
,
encoding
:
{
x
:
{
field
:
"location"
,
type
:
"nominal"
,
sort
:
'*'
}
,
y
:
{
field
:
"count"
,
type
:
"quantitative"
}
,
color
:
{
"field"
:
"location"
,
"type"
:
"nominal"
}
}
}
)
Insert cell
Insert cell
notNull
=
z
.
filter
(
r
=>
r
.
lat
!=
null
,
tweetsDF
)
Insert cell
vegalite
(
{
data
:
{
values
:
notNull
}
,
mark
:
"point"
,
encoding
:
{
x
:
{
field
:
"lon"
,
type
:
"quantitative"
}
,
y
:
{
field
:
"lat"
,
type
:
"quantitative"
}
}
}
)
Insert cell
Insert cell
// Loop through all the locations, and see if they are similar to Boston, then create a new column
newTweets
=
{
let
newLocations
=
[
]
let
locations
=
z
.
getCol
(
"location"
,
tweetsDF
)
for
(
let
id
in
locations
)
{
if
(
locations
[
id
]
.
toLowerCase
(
)
.
includes
(
'boston'
)
)
{
newLocations
.
push
(
'Boston, MA'
)
}
else
{
newLocations
.
push
(
locations
[
id
]
)
}
}
return
z
.
addCol
(
"cleanLocations"
,
newLocations
,
tweetsDF
)
}
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
resolveAfter2Seconds
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
f1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
vegalite
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
z
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
text
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tweetsStrings
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tweetsDF
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
count
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
countSorted
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
notNull
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
newTweets
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML