Using in the browser
The redivis-js library runs in the browser as well as in Node.js, so you can build web applications, dashboards, and interactive notebooks (e.g., on Observable) on top of data in Redivis.
Embed in an HTML page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Redivis query example</title>
</head>
<body>
<script type="module">
import redivis from 'https://cdn.jsdelivr.net/npm/redivis/+esm';
const rows = await redivis
.query(`
SELECT FIREYEAR, COUNT(*) AS count
FROM demo.us_forest_service_fires.us_fire_perimeters
GROUP BY FIREYEAR
ORDER BY FIREYEAR
`)
.toRowsArray();
console.log(rows);
</script>
</body>
</html>Authenticate users
Public data can be read without authenticating. When a resource requires it, the library opens a popup for the user to sign in to Redivis. Since browsers may block popups that aren't opened in response to a user action, call authorize() from a click handler when you know authentication will be needed:
The token obtained is held only for the current tab, and is read-only unless a request requires more access.
Read data through your own server
To show data that requires authentication to users without a Redivis account — without exposing your credentials — route the library's requests through your own server. The server adds an API token to each request, and forwards it to https://redivis.com/api/v1:
Memory limits
To protect the browser tab from running out of memory, toArrowTable() and toRowsArray() read at most 100MB by default in the browser, throwing a ValueError for larger reads. Select fewer variables or rows, raise the limit with maxBytes, or stream the data with toArrowBatchIterator():
Visualize data
Arrow tables can be passed directly to many visualization and analysis libraries:
See Reading tabular data for more.
Cancel reads
Pass an AbortSignal to cancel a read — e.g., when the user navigates away, or changes a filter before the previous read finishes:
Limitations
Functionality that needs a filesystem is only available in Node.js: downloading tables, files, and directories; uploading from a file path; and adding the files of a local directory to a table. In the browser, read data and files into memory (or stream them) instead, and upload Files and Blobs.
Was this helpful?

