-
Notifications
You must be signed in to change notification settings - Fork 4
/
report_example.py
87 lines (64 loc) · 1.51 KB
/
report_example.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import altair as alt
from vega_datasets import data
import figurl as fig
report = fig.Report()
report.add_markdown('''
# Example report
A figurl report consists of a collection of sections
that are laid out vertically in a scrollable figure.
First initiate the report:
```python
import figurl as fig
report = fig.Report()
```
Add a markdown item:
```python
source = '...'
report.add_markdown(source)
```
Add a chart:
```python
chart = ... # define an altair chart
report.add_altair_chart(chart)
```
Add more markdown:
```python
report.add_markdown('...')
```
Generate the figURL
```python
url = report.url(label='Example report')
print(url)
```
Here is an example chart:
''')
# Add an altair chart
iris = data.iris()
chart = alt.Chart(iris).mark_point().encode(
x='petalLength',
y='petalWidth',
color='species'
)
report.add_altair_chart(chart)
report.add_markdown('''
## Horizontal layouts
You can also add horizontal layout items and insert items
onto the layout:
```python
chart1 = ... # define an altair chart
chart2 = ... # define an altair chart
layout = report.add_hboxlayout()
layout.add_altair_chart(chart1)
layout.add_altair_chart(chart2)
```
Here is an example horizontal layout item:
''')
chart1 = chart
chart2 = chart
layout = report.add_hboxlayout()
layout.add_altair_chart(chart1)
layout.add_altair_chart(chart2)
url = report.url(label='Example report')
print(url)
# Output:
# https://figurl.org/f?v=gs://figurl/figurl-report&d=sha1://e0f267258f432adcb89c5379c4136c3f00fbce78&label=Example%20report