Skip to content

Text, Formulas, Code, and HTML

Datapane allows you to add markdown text to your reports, including helpers for creating text-heavy Python reports.

Text

The best way to include long-form text is to use the Web Editor, which allows you to add and edit text directly in the browser, and preview the result.

However, you can still add text from within your Python script, as follows:

import datapane as dp

report = dp.Report(dp.Text("__My awesome markdown__"))
report.save("text.html")

Info

Markdown is a lightweight markup language that allows you to include formatted text in your report, and can be access through dp.Text, or by passing in a string directly.

To include multi-line text and formatting the words, use triple-quoted string, e.g. """Some words"""

import datapane as dp

md = """Quas *diva coeperat usum*; suisque, ab alii, prato. Et cornua frontes puerum,
referam vocassent **umeris**. Dies nec suorum alis adstitit, *temeraria*,
anhelis aliis lacunabant quoque adhuc spissatus illum refugam perterrita in
sonus. Facturus ad montes victima fluctus undae Zancle et nulli; frigida me.
Regno memini concedant argento Aiacis terga, foribusque audit Persephone
serieque, obsidis cupidine qualibet Exadius.

```python
utf_torrent_flash = -1;
urlUpnp -= leakWebE - dslam;
skinCdLdap += sessionCyberspace;
var ascii = address - software_compile;
webFlaming(cable, pathIllegalHtml);```

## Quo exul exsecrere cuique non alti caerulaque

*Optatae o*! Quo et callida et caeleste amorem: nocet recentibus causamque.

- Voce adduntque
- Divesque quam exstinctum revulsus
- Et utrique eunti
- Vos tantum quercum fervet et nec
- Eris pennis maneas quam
"""

report = dp.Report(dp.Text(md))
report.save(path="multi-line.html")

Info

Check here for more information on how to format your text with markdown.

Text-heavy Reports

If your report is text-heavy (such as an blogpost) and it contains multiple other blocks, creating a list of strings and blocks in Python can be cumbersome. To solve this, Datapane provides a format option, which allows you to write a single block of Markdown (either in your report, or in a separate file), and intersperse it with other blocks.

To do this, use double braces to specify where you want your other blocks to appear throughout your text.

import seaborn as sns
import altair as alt
import datapane as dp

md = """
For example, if we want to visualize the number of people in each class within the interval we select a point chart between age and fare, we could do something like this.

{{plot}}

Altair allows you to create some extremely interactive plots which do on-the-fly calculations — without even requiring a running Python server!
"""

titanic = sns.load_dataset("titanic")

points = (
    alt.Chart(titanic)
    .mark_point()
    .encode(
        x="age:Q",
        color="class:N",
        y="fare:Q",
    )
    .interactive()
    .properties(width="container")
)

report = dp.Report(dp.Text(md).format(plot=points))

report.save(path="text-heavy.html")

Alternatively, you can write your article or post in your favourite markdown editor, and pass it in as a file.

import datapane as dp

...

dp.Report(
  dp.Text(file="./my_blogpost.md").format(plot=points)
)

Formulas

The formula block allows you easily to add LaTeX-formatted equations to your report, with an optional caption. A brief intro into LaTeX formulas can be found here.

import datapane as dp

report = dp.Report(dp.Formula(r"\frac{1}{\sqrt{x^2 + 1}}"))

report.save(path="formula.html")

Info

LaTeX formulas commonly make use of special characters, hence prefix your formulas with r in Python as per the example above to make them raw strings, e.g. r"x^2"

Under the hood we use MathJAX to render the equations in the browser and not a full TeX engine. This means that some of your TeX input may not be rendered correctly on our system - read the MathJAX documentation for more info.

Code

The code block allows you to embed syntax highlighted source code into your report. This block currently supports Python and JavaScript.

import datapane as dp

code = """
function foo(n) {
  return foo(n + 1)
}
"""

report = dp.Report(dp.Code(code=code, language="javascript"))
report.save(path="code.html")

HTML

The HTML block allows you to add raw HTML to your report, allowing for highly customized components, such as your company's brand, logo, and more.

Info

The HTML component is sandboxed and cannot execute JavaScript.

import datapane as dp

html = """
<html>
    <style type='text/css'>
        @keyframes example {
            0%   {color: #EEE;}
            25%  {color: #EC4899;}
            50%  {color: #8B5CF6;}
            100% {color: #EF4444;}
        }
        #container {
            background: #1F2937;
            padding: 10em;
        }
        h1 {
            color:#eee;
            animation-name: example;
            animation-duration: 4s;
            animation-iteration-count: infinite;
        }
    </style>
    <div id="container">
      <h1> Welcome to my Report </h1>
    </div>
</html>
"""

report = dp.Report(dp.HTML(html))

report.save(path="html.html")