Public
Edited
Oct 25, 2023
1 fork
Insert cell
Insert cell
url = `https://www.insee.fr/fr/statistiques/fichier/6800675/v_commune_2023.csv`
Insert cell
proxy = "https://corsproxy.io/?"
Insert cell
d3.csv(proxy + url)
Insert cell
db = {
const configuredClient = await DuckDBClient.of();

await configuredClient.query(`
CREATE VIEW cog AS
SELECT * FROM read_csv_auto('${proxy + url}') ;
`);
await configuredClient.query(`
CREATE VIEW bureau_vote AS
SELECT * FROM read_parquet('https://www.data.gouv.fr/fr/datasets/r/6faacf36-1897-43f5-bf39-af8b41a15d26') ;
`);

return configuredClient
}
Insert cell
Inputs.table(
db.query(`SELECT * FROM cog LIMIT 5`)
)
Insert cell
Inputs.table(
db.query(`SELECT * FROM bureau_vote LIMIT 5`)
)
Insert cell
url_table_logement = "https://static.data.gouv.fr/resources/recensement-de-la-population-fichiers-detail-logements-ordinaires-en-2020-1/20231023-123618/fd-logemt-2020.parquet"
Insert cell
url_table_individu = "https://static.data.gouv.fr/resources/recensement-de-la-population-fichiers-detail-individus-localises-au-canton-ou-ville-2020-1/20231023-122841/fd-indcvi-2020.parquet"
Insert cell
url_doc = "https://www.data.gouv.fr/fr/datasets/r/8a287ffb-7614-4b47-9cfa-7990ce89e1ce"
Insert cell
renommage_documentation = `SELECT
COD_VAR AS nom_variable,
LIB_VAR AS description_variable,
TYPE_VAR AS type_variable,
COD_MOD AS code_modalite,
LIB_MOD AS description_modalite`
Insert cell
db2 = {
const configuredClient = await DuckDBClient.of();

await configuredClient.query(`
CREATE OR REPLACE VIEW table_individu
AS SELECT *
FROM read_parquet('${url_table_individu}')`
) ;

await configuredClient.query(`
CREATE OR REPLACE VIEW table_logement
AS SELECT *
FROM read_parquet('${url_table_logement}')`
) ;

await configuredClient.query(`
CREATE OR REPLACE VIEW documentation
AS ${renommage_documentation} FROM read_csv_auto('${url_doc}', header=true)`
) ;

return configuredClient
}

Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
liste_regions = ["11", "31", "34"]
Insert cell
liste_regions_sql = liste_regions.map(item => `'${item}'`).join(",")
Insert cell
Inputs.table(
db2.query(`SELECT * FROM table_individu WHERE DEPT IN (?) LIMIT 10`, [liste_regions_sql])
)
Insert cell
Inputs.table(
db2.query(`SELECT * FROM table_individu WHERE DEPT IN (${liste_regions_sql}) LIMIT 10`)
)
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