Advanced Embedding

Learn how to embed subsets of your reports via queries

Overview

Many times, your report will have different blocks, but you may wish to share only a subset, for instance it's often useful to embed a specific chart or dataset into another platform - especially if you are refreshing it on a cadence.

Instead of creating a report for each block, Datapane provides an blocksquery parameter you can add to your report link that allows you to query your report using XPath, so you can embed only the relevant blocks.

Here are a few of the most common examples and use-cases you will encounter.

Querying by Block id

The easiest way to embed only a single block is to assign an id to your block when creating it, e.g. dp.Plot(plot, id="my-plot"), and then use a simple query of the following form to select it in your embed URL,

https://datapane.com/u/user/reports/report-name?blocksquery=//*[@id='my-plot']

where //*[@id="my-plot"] is an XPath query that will extract any report block with the id of my-plot.

For instance, the plot in this report has an id of block-7, and so the following query will select just that plot: https://datapane.com/leo/reports/continent_covid_cases/?blocksquery=//*[@id='block-7']

Querying by Block type and index

As mentioned, Reports are comprised of multiple block types, such as Plot, Table, Text, and so on - we can select just blocks of a specific type also using XPath, and even select the specific index of a particular block type or a range.

Let's say there are both Table and Plot blocks in your report, and you want to only embed the plots from your report. Simply add /?blocksquery=//Plot at the end of the report link. For example, to extract all the plots in this report you can use the following query,

https://datapane.com/u/leo/reports/google-trends/embed/?blocksquery=//Plot

If you want to query only the first plot of the report, just add an index to the Plot query, i.e., /?blocksquery=//Plot[1], e.g.

https://datapane.com/u/leo/reports/google-trends/embed/?blocksquery=//Plot[1] will select the first plot, and https://datapane.com/u/leo/reports/google-trends/embed/?blocksquery=//Plot[2] will the second.

Querying by Block type will also remove all layout information from the report, making it easier to view when embedded