Published
Edited
Aug 20, 2021
2 stars
Insert cell
Insert cell
Insert cell
url = "https://datahub.io/machine-learning/iris/r/iris.csv"
Insert cell
fetch(url).then(response => response.text())
Insert cell
(await fetch(url)).text()
Insert cell
d3.text(url)
Insert cell
md`#### Text Input from attached file`
Insert cell
FileAttachment("iris_csv.csv").text()
Insert cell
md`### CSV data input`
Insert cell
d3.csv(url)
Insert cell
d3.csv(url, d3.autoType)
Insert cell
inputText = d3.text(url) // Or any other text file input method shown above
Insert cell
d3.csvParse(inputText)
Insert cell
d3.csvParse(inputText, d3.autoType)
Insert cell
md`#### CSV data input from an attached file`
Insert cell
FileAttachment("iris_csv.csv").csv({ typed: true })
Insert cell
FileAttachment("iris_csv.csv").csv({ typed: true, array: true })
Insert cell
d3.csvParse(await FileAttachment("iris_csv.csv").text())
Insert cell
Insert cell
xlsx = require("xlsx")
Insert cell
md`#### Reading a CSV file using xlsx library`
Insert cell
ab = FileAttachment("iris_csv.csv").arrayBuffer()
Insert cell
wb = xlsx.read(ab, { type: 'array' })
Insert cell
viewof sheet_name = Inputs.select(
wb.SheetNames,
{
label: "Choose Sheet"
}
)
Insert cell
ws = wb.Sheets[sheet_name]
Insert cell
xlsx.utils.sheet_to_json(ws)
Insert cell
headers = Object.keys(xlsx.utils.sheet_to_json(ws)[0])
Insert cell
md`#### Reading a sample Excel file using xlsx library
File source: https://dornsife.usc.edu › docs › ir211wk12sample`
Insert cell
ab1 = FileAttachment("ir211wk12sample.xls").arrayBuffer()
Insert cell
wb1 = xlsx.read(ab1, { type: 'array' }) // wb1 = xlsx.read(new Uint8Array(ab1), { type: 'array' })
Insert cell
viewof sheet_name1 = Inputs.select(wb1.SheetNames, {
label: "Choose Sheet"
})
Insert cell
ws1 = wb1.Sheets[sheet_name1]
Insert cell
xlsx.utils.sheet_to_json(ws1)
Insert cell
Inputs.table(xlsx.utils.sheet_to_json(ws1))
Insert cell
import { soFetch } from '@alecglassford/so-fetch'
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