Requesting data from embedded apps
You can request content from Juicebox tables in embedded apps and check if the report is fully loaded.
Last updated
Was this helpful?
You can request content from Juicebox tables in embedded apps and check if the report is fully loaded.
Last updated
Was this helpful?
You can request the current filtered state of a Juicebox table. This can return either a downloadable file for your user or a json object that can be used to for other automations.
Juicebox uses the javacsript api to safely allow cross origin communication between window objects. Juicebox listens for postMessage events. Juicebox filters postMessage messages to an allowed origin page (currently all Juicebox servers). Your Juicebox representative can ensure your site or test site is whitelisted.
The messages can call is-report-ready, export-data, or download-data.
In order to export or download data, you must confirm that the Juicebox report is fully loaded. To do so, you can poll the Juicebox report with is-report-ready. A javascript sample looks like this.
Your page should register an event listener to receive the callback.
In this example, the Juicebox app is iframed in an iframe with id #juicebox-iframe. Table1 is the identifier for the table you want to download.
Alternatively, once a report is fully loaded, use export-data to return data from a table as a json object.
As with downloading data, the Juicebox app is iframed in an iframe with id #juicebox-iframe. Table1 is the identifier for the table you want to export.
The response will be a json object containing the following keys.
columns
: A list of columns objects in the order that they appear with column metadata. The properties of each column are:
name
: The display name of the column as it appears in the header of the table.
field
: The property on each row that contains the value.
dtype
: The datatype of the column. One of the following
str
: String
num
: Numeric
date
: Date, the values will be formatted as ISO-8601 formatted strings
datetime
: Datetimes, the values will be formatted as ISO-8601 formatted strings
bool
: Boolean values
data
: A list of rows. Each row will contain all the columns in the column list.
Here is a sample response:
download-data or export-data request may take several seconds to return. Your page should register an event listener to receive the callback containing the data, like this example. The callback will be a message event with origin matching the Juicebox server.
This html file provides a sample implementation of how to communicate with a Juicebox app in an iframe. You should view the source of this file to see how the communication works.
To use this file, you'll need:
Your juicebox servername, typically "https://MYSITE.myjuicebox.io" which you will enter in the site URL.
A Juicebox Access View key. Your Juicebox representative can help you get this.
Click "Embed It!" to first create an embedded Juicebox iframe.
Next you need the slug of a table in the app you've embedded.
Choose either "Export Data" or "Download Data".
Choosing "Export Data" will log the returned data in the browser console.
Choosing "Download Data" will perform the download.
Once the report is , you can request downloadable data. This will return a time-limited url that can be used to download the content. The download data request looks like:
format
: A juicebox formatting string. For dates and datetimes, these correspond to strftimes. For numbers, the formats are an extension of d3.format which supports different formats for positive, negative, null, and zero values, as well as prefix and suffix support.