Skip to content

Commit dd5772e

Browse files
authored
Merge pull request #487 from facultyai/faq
Add FAQ to docs
2 parents 6e3b702 + 274792e commit dd5772e

File tree

4 files changed

+130
-2
lines changed

4 files changed

+130
-2
lines changed

docs/components_page/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def register_apps():
108108
"label": "Quickstart",
109109
},
110110
{"name": "themes", "href": "/docs/themes", "label": "Themes"},
111+
{"name": "faq", "href": "/docs/faq", "label": "FAQ"},
111112
{"name": "dashr", "href": "/docs/dashr", "label": "Dash for R"},
112113
{
113114
"name": "components",

docs/content/docs/faq.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: FAQ
3+
---
4+
5+
# Frequently Asked Questions
6+
7+
This page contains various tips and tricks and answers to frequently asked questions about _dash-bootstrap-components_. If you think something is missing, please submit an [issue][issue] on the GitHub issue tracker.
8+
9+
### Using Bootstrap and `dash_table.DataTable` together
10+
11+
Bootstrap CSS defines a CSS class called `row`, which is a key part of the Bootstrap grid system. The `DataTable` component applies the `row` class to rows in the table, which causes a clash and breaks some of the formatting of the table. In particular the table can overflow its container, and dropdowns aren't rendered correctly.
12+
13+
The solution is to prevent the Bootstrap row styles from being applied to rows in the table. There are two ways to do this. The first way, which is maybe more convenient if you just have a single table, is to pass additional arguments to the `css` prop of `DataTable` like this
14+
15+
```python
16+
DataTable(..., css=[{"selector": ".row", "rule": "margin: 0; display: block"}])
17+
```
18+
19+
Alternatively, you can write the following custom CSS to apply the styles to all tables in your app.
20+
21+
```css
22+
.dash-table-container .row {
23+
display: block;
24+
margin: 0;
25+
}
26+
```
27+
28+
See the [Dash docs](https://dash.plotly.com/external-resources) for details on linking custom stylesheets.
29+
30+
### How do I use `Tooltip` or `Popover` with pattern-matching callbacks?
31+
32+
Dash 1.11.0 added support for [pattern matching callbacks](https://dash.plotly.com/pattern-matching-callbacks) which allows you to write callbacks that can update an arbitrary or dynamic number of Dash components. To enable this, the `id` of a Dash component can now be a Python dictionary, and the callback is triggered based on a matching rule with one or more of the keys in this dictionary.
33+
34+
However, it is not possible to use a dictionary as the `target` of the `Popover` or `Tooltip` components. The reason for this is explained below. To get around the problem, the best thing to do is to wrap your dynamically created components with a `html.Div` element or similar, and use a string `id` for the wrapper which you then use as the target for the `Tooltip` or `Popover`. For example this example from the Dash documentation
35+
36+
```python
37+
@app.callback(
38+
Output('dropdown-container', 'children'),
39+
Input('add-filter', 'n_clicks'),
40+
State('dropdown-container', 'children'))
41+
def display_dropdowns(n_clicks, children):
42+
new_dropdown = dcc.Dropdown(
43+
id={
44+
'type': 'filter-dropdown',
45+
'index': n_clicks
46+
},
47+
options=[{'label': i, 'value': i} for i in ['NYC', 'MTL', 'LA', 'TOKYO']]
48+
)
49+
children.append(new_dropdown)
50+
return children
51+
```
52+
53+
might become the following
54+
55+
```python
56+
@app.callback(
57+
Output('dropdown-container', 'children'),
58+
Input('add-filter', 'n_clicks'),
59+
State('dropdown-container', 'children'))
60+
def display_dropdowns(n_clicks, children):
61+
new_dropdown = html.Div(
62+
dcc.Dropdown(
63+
id={
64+
'type': 'filter-dropdown',
65+
'index': n_clicks
66+
},
67+
options=[{'label': i, 'value': i} for i in ['NYC', 'MTL', 'LA', 'TOKYO']]
68+
),
69+
id=f"dropdown-wrapper-{n_clicks}"
70+
)
71+
new_tooltip = dbc.Tooltip(
72+
f"This is dropdown number {n_clicks}",
73+
target=f"dropdown-wrapper-{n_clicks}",
74+
)
75+
children.append(new_dropdown)
76+
children.append(new_tooltip)
77+
return children
78+
```
79+
80+
The reason `Popover` and `Tooltip` can't support the dictionary-based `id` is that under the hood these components are searching for the `id` using a function called `querySelectorAll` implemented as part of the standard Web APIs. This function can only search for a valid CSS selector string, which is restricted more or less to alphanumeric characters plus hyphens and underscores. Dash serialises dictionary ids as JSON, which contains characters like `{` and `}` that are invalid in CSS selectors. The above workaround avoids this issue.
81+
82+
### How do I scale the viewport on mobile devices?
83+
84+
When building responsive layouts it is typical to have something like the following in your HTML template
85+
86+
```html
87+
<meta name="viewport" content="width=device-width, initial-scale=1" />
88+
```
89+
90+
this ensures that mobile devices don't rescale your content on small screens and lets you build mobile optimised layouts. See [here](https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag) for a great explanation.
91+
92+
To achieve the same thing in Dash, use the `metas` keyword argument in the `Dash` constructor.
93+
94+
```python
95+
app = dash.Dash(
96+
external_stylesheets=[dbc.themes.BOOTSTRAP],
97+
meta_tags=[
98+
{"name": "viewport", "content": "width=device-width, initial-scale=1"},
99+
],
100+
)
101+
```
102+
103+
### How do I make the `Popover` wider?
104+
105+
Bootstrap sets the `max-width` of the popover in the `.popover` CSS class. You can overwrite this, either by using a local copy of Bootstrap CSS and editing the file, or by adding a snippet like the following to your `assets/` folder.
106+
107+
```css
108+
.popover {
109+
max-width: 400px;
110+
}
111+
```
112+
113+
See the [Dash docs](https://dash.plotly.com/external-resources) for details on linking custom stylesheets.
114+
115+
[issue]: https://github.com/facultyai/dash-bootstrap-components/issues/new?template=feature.md

docs/server.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
DOCS_SIDENAV_ITEMS = [
55
{"name": "quickstart", "href": "/docs/quickstart", "label": "Quickstart"},
66
{"name": "themes", "href": "/docs/themes", "label": "Themes"},
7+
{"name": "faq", "href": "/docs/faq", "label": "FAQ"},
78
{"name": "dashr", "href": "/docs/dashr", "label": "Dash for R"},
89
{"name": "components", "href": "/docs/components", "label": "Components"},
910
]
@@ -42,6 +43,17 @@ def themes():
4243
except TemplateNotFound:
4344
abort(404)
4445

46+
@server.route("/docs/faq/")
47+
def faq():
48+
try:
49+
return render_template(
50+
"generated/docs/faq.html",
51+
sidenav_items=DOCS_SIDENAV_ITEMS,
52+
sidenav_active="faq",
53+
)
54+
except TemplateNotFound:
55+
abort(404)
56+
4557
@server.route("/docs/dashr/")
4658
def dashr():
4759
try:

docs/templates/examples-index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ <h2>Graphs in <code>Tabs</code></h2>
4545
/></a>
4646
</div>
4747
<p>
48-
An example app showing how to ensure `dash_core_components.Graph`
49-
components are sized correctly when used with `dbc.Tabs`.
48+
An example app showing how to ensure <code>dash_core_components.Graph</code>
49+
components are sized correctly when used with <code>dbc.Tabs</code>.
5050
</p>
5151
</div>
5252
<div class="col-12 col-md-4">

0 commit comments

Comments
 (0)