forked from radovankavicky/dash-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_components.py
More file actions
117 lines (92 loc) · 3.98 KB
/
Copy pathhtml_components.py
File metadata and controls
117 lines (92 loc) · 3.98 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- coding: utf-8 -*-
import dash_core_components as dcc
import dash_html_components as html
import styles
layout = html.Div(children=[
dcc.Markdown('''
# Dash HTML Components
Dash is a web application framework that provides pure Python abstraction
around HTML, CSS, and JavaScript.
Instead of writing HTML or using an HTML templating engine,
you compose your layout using Python structures with the
`dash-html-components` library.
The source for this library is on GitHub: [plotly/dash-html-components](https://github.com/plotly/dash-html-components).
Here is an example of a simple HTML structure:
'''.replace(' ', '')),
dcc.SyntaxHighlighter('''import dash_html_components as html
html.Div([
html.H1('Hello Dash'),
html.Div([
html.P('Dash converts Python classes into HTML'),
html.P('This conversion happens behind the scenes by Dash\'s JavaScript front-end')
])
])''', language='python', customStyle={'borderLeft': 'thin solid lightgrey'}),
html.Div(
'which gets converted (behind the scenes) into the '
'following HTML in your web-app:'
),
dcc.SyntaxHighlighter('''<div>
<h1>Hello</h1>
<div>
<p>Dash converts Python classes into HTML</p>
<p>This conversion happens behind the scenes by Dash's JavaScript front-end</p>
</div>
</div>''', language='python', customStyle={'borderLeft': 'thin solid lightgrey'}),
dcc.Markdown('''
If you're not comfortable with HTML, don't worry!
You can get 95% of the way there with just a few elements
and attributes.
Dash's [core component library](/dash-core-components) also supports
[Markdown](http://commonmark.org/help).
'''.replace(' ', '')),
dcc.SyntaxHighlighter('''import dash_core_components as dcc
dcc.Markdown(\'\'\'
#### Dash and Markdown
Dash supports [Markdown](http://commonmark.org/help).
Markdown is a simple way to write and format text.
It includes a syntax for things like **bold text** and *italics*,
[links](http://commonmark.org/help), inline `code` snippets, lists,
quotes, and more.
\'\'\')
'''.replace(' ', ''),
customStyle=styles.code_container,
language='python'
),
dcc.Markdown('''
#### Dash and Markdown
Dash supports [Markdown](http://commonmark.org/help).
Markdown is a simple way to write and format text.
It includes a syntax for things like **bold text** and *italics*,
[links](http://commonmark.org/help), inline `code` snippets, lists,
quotes, and more.'''.replace(' ', ''),
containerProps={'className': 'example-container'}),
dcc.Markdown('''
If you're using HTML components, then you also access to
properties like `style`, `class`, and `id`.
All of these attributes are available in the Python classes.
The HTML elements and Dash classes are mostly the same but there are
a few key differences:
- The `style` property is a dictionary
- Properties in the `style` dictionary are camelCased
- The `class` key is renamed as `className`
- Style properties in pixel units can be supplied as just numbers without the `px` unit
Let's take a look at an example.
'''.replace(' ', '')),
dcc.SyntaxHighlighter('''import dash_html_components as html
html.Div([
html.Div('Example Div', style={'color': 'blue', 'fontSize': 14}),
html.P('Example P', className='my-class', id='my-p-element')
], style={'marginBottom': 50, 'marginTop': 25})
''', language='python', customStyle=styles.code_container),
html.Div('That dash code will render this HTML markup:'),
dcc.SyntaxHighlighter('''
<div style="margin-bottom: 50px; margin-top: 25px;">
<div style="color: blue; font-size: 14px">
Example Div
</div>
<p class="my-class", id="my-p-element">
Example P
</p>
</div>
''', language='html', customStyle=styles.code_container)
])