Skip to content

Text

You can add short or long-form Markdown content to your app with the Text block.

Info

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

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

Simple Text from Markdown

import datapane as dp

app = dp.App(dp.Text("__My awesome markdown__"))
app.save("simple-text.html")

Multi-line Text

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
"""

app = dp.App(dp.Text(md))
app.save(path="multi-line.html")

Text-heavy apps

If your app 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 app, 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")
)

app = dp.App(dp.Text(md).format(plot=points))

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

Text from File

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.App(
  dp.Text(file="./my_blogpost.md").format(plot=points)
)