Py.Cafe

antonymilne/

vizro-flex-text-renderer-0

Enhanced Flex-based Text Renderer

DocsPricing
  • assets/
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from vizro import Vizro
import vizro.models as vm

justify_options = [
    "start",
    "end",
    "center",
    "between",
    # "around",
    # "evenly",
]

align_options = [
    "start",
    "end",
    "center",
    "stretch"
]

class Flex(vm.Flex):
    justify: str
    align: str
    def build(self):
        flex = super().build()
        flex.className += f" justify-content-{self.justify} align-items-{self.align}"
        return flex

page = vm.Page(
    title="Different justification option",
    layout=vm.Flex(direction="column"),
    components = [
        vm.Container(
            layout=Flex(direction="row", justify=justify, align=align),
            title=f"{justify=} {align=}",
            components=[vm.Card(text="text")] * 2 + [vm.Card(text="text\n\ntext")]
        )
        for justify in justify_options for align in align_options
    ]
)

dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()