Files, Images and Embeds

Files and Images

The File block allows you to include files in your reports. If the file is in a supported format, it will be displayed inline in your report. If the format cannot be rendered, it will present the viewer with the option to download the file. This block is useful for including images, JSON data, Excel files, and PDFs for your viewers.
To include a file, you can use dp.File and pass the path.
1
dp.File(file='./image.jpeg')
Copied!
In the following example, Datapane will attempt to display images and JSON in your report for viewers and allow users to download them.
1
import datapane as dp
2
3
report = dp.Report(
4
dp.File(file="./image.jpeg"),
5
dp.File(file="./data.xlsx"),
6
dp.File(file="./config.json")
7
)
8
report.upload(name='Files Sample')
Copied!
caption support for images is coming soon!

Python objects

Alternatively, instead of passing in a path of a file, you can pass in an object such as a Python dictionary, and use is_json to tell Datapane to attempt to render it in JSON format in the front-end, where the user will be able to explore and download it.
1
import datapane as dp
2
3
thisdict = {
4
"brand": "Ford",
5
"model": "Mustang",
6
"year": 1964
7
}
8
9
dp.Report(dp.File(thisdict, is_json=True, name='thisdict')).upload(name='json')
Copied!

Embeds

The Embed block lets you embed content from other platforms e.g. Youtube, Spotify. This is how you'd use it:
Python
Text Report
1
import datapane as dp
2
3
dp.Report(
4
dp.Embed(url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')
5
).upload(name='Embex example')
Copied!
1
```datapane
2
block: embed
3
url: https://www.youtube.com/watch?v=dQw4w9WgXcQ
4
caption: Youtube video
5
```
Copied!
You don't need to use this block for simple embeds on TextReports like GIFs. For those, just use Markdown syntax i.e. ![](https://my-example-gif.gif)
If you're trying to embed an iframe, you can wrap it in an HTML block.
Last modified 17d ago