Skip to main content

random_id()

Helper for creating a random id for an output table.

Usage

Source

random_id(n=10)

A table’s id is the id= attribute of the HTML element that holds it, which CSS (as in opt_css()) can use to target that table alone. Give one with GT(id=) or with_id().

Parameters

n: int = 10
The number of lowercase letters to use in the random ID string. Defaults to 10.

Returns

str
A string that constitutes a random ID value.

Examples

Each call gives a new string of random lowercase letters.

from great_tables import random_id

random_id(), random_id(n=5)
('dobgsiinah', 'tffgm')

Here, the table gets a random ID, which its CSS is then scoped to.

from great_tables import GT, exibble

GT(exibble[["num", "char"]].head(3)).with_id(random_id())
num char
0.1111 apricot
2.222 banana
33.33 coconut