Skip to content

Commit 181a4ed

Browse files
committed
Fix demos and docs for dash 2.5
1 parent db156eb commit 181a4ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+246
-304
lines changed

docs/08-MultiPageDashApp.md

+28-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
> ## Status: Multi-Page Dash App Plugin
3-
> #### Under active development: A plugin to simplify creating multi-page Dash apps. This is a preview of functionality that will be added to Dash 2.x.
3+
> #### The `pages` functionality is now part of dash 2.5! These docs remain here for legacy purposes. `pages` is a plugin to simplify creating multi-page Dash apps.
44
> **[See the community announcement for details and discussion](https://community.plotly.com/t/introducing-dash-pages-dash-2-1-feature-preview/57775)**
55
66

@@ -80,18 +80,19 @@ if __name__ == "__main__":
8080

8181
4. Create a folder called `pages/` and place your app layouts in files within that folder. Each file needs to:
8282
- Define `layout`. This can be a variable or function that returns a component
83-
- Call `dash.register_page(__name__)` to tell `dl.plugins.pages` that this page should be part of the multi-page framework
83+
- Call `dl.plugins.register_page(__name__)` to tell `dl.plugins.pages` that this page should be part of the multi-page framework
8484

8585
For example, here is the first page of our app:
8686

8787
[`demos/multi-page-example1/pages/heatmaps.py`](docs/demos/multi-page-example1/pages/heatmaps.py)
8888

8989
```python
90-
import dash
91-
dash.register_page(__name__, path="/")
90+
from dash_labs.plugins import register_page
91+
9292
from dash import Dash, dcc, html, Input, Output, callback
9393
import plotly.express as px
9494

95+
register_page(__name__, path="/")
9596
df = px.data.medals_wide(indexed=True)
9697

9798
layout = html.Div(
@@ -115,8 +116,8 @@ def filter_heatmap(cols):
115116
```
116117

117118
The `dash.page_registry` is an `OrderedDict` with keys being the page's module name (e.g. `pages.bar-charts`) and values being a dictionary containing keys `path`, `name`, `order`, `title`, `description`, `image`, and `layout`.
118-
As you saw in the above example, This `page_registry` is populated from calling `dash.register_page` within `pages/`.
119-
`dash.register_page` will accept various arguments to customize aspects about the page. See the Advanced Features section below.
119+
As you saw in the above example, This `page_registry` is populated from calling `register_page` within `pages/`.
120+
`register_page` will accept various arguments to customize aspects about the page. See the Advanced Features section below.
120121

121122

122123
![multi_page](https://user-images.githubusercontent.com/72614349/140232399-efe7020d-480a-40af-a0b0-40e66dcd9d56.gif)
@@ -133,16 +134,16 @@ These features are all optional. If you don't supply values here, the framework
133134

134135
The page's title defines what you see in your browser tab and what would appear as the website's title in search results. By default, it is derived from the filename but it can also be set with `title=`
135136
```
136-
dash.register_page(__name__, title='Custom page title')
137+
dl.plugins.register_page(__name__, title='Custom page title')
137138
```
138139

139140
Similarly, the meta description can be set with `description=` and the meta image can be set with `image=`. Both of these tags are used as the preview when sharing a URL in a social media platforms. They're also used in search engine results.
140141

141142
By default, Dash will look through your `assets/` folder for an image that matches the page's filename or else an image called `app.<image_extension>` (e.g. `app.png` or `app.jpeg`) or `logo.<image_extension>` (all image extensions are supported).
142143

143-
This image URL can also be set directly with `app.register_page(image=...)` e.g.
144+
This image URL can also be set directly with `dl.plugins.register_page(image=...)` e.g.
144145
```python
145-
app.register_page(__name__, image='/assets/page-preview.png')
146+
dl.plugins.register_page(__name__, image='/assets/page-preview.png')
146147
```
147148

148149
**`dash.page_registry`**
@@ -152,7 +153,7 @@ app.register_page(__name__, image='/assets/page-preview.png')
152153
For example:
153154
`pages/historical_analysis.py`
154155
```
155-
dash.register_page(__name__)
156+
dl.plugins.register_page(__name__)
156157
157158
print(dash.page_registry)
158159
```
@@ -171,7 +172,7 @@ OrderedDict([
171172
Whereas:
172173
`pages/outlook.py`
173174
```
174-
dash.register_page(__name__, path='/future', name='Future outlook', order=4)
175+
dl.plugins.register_page(__name__, path='/future', name='Future outlook', order=4)
175176
176177
print(dash.page_registry)
177178
```
@@ -196,7 +197,7 @@ OrderedDict values can be accessed just like regular dictionaries:
196197

197198
The order of the items in `page_registry` is based off of the optional `order=` parameter:
198199
```python
199-
dash.register_page(__name__, order=10)
200+
dl.plugins.register_page(__name__, order=10)
200201
```
201202

202203
If it's not supplied, then the order is alphanumeric based off of the filename. This order is important when rendering the page menu's dynamically in a loop. The page with the path `/` has `order=0` by default.
@@ -208,7 +209,7 @@ Redirects can be set with the `redirect_from=[...]` parameter in `register_page`
208209

209210
`pages/historical_analysis.py`
210211
```
211-
dash.register_page(
212+
dl.plugins.register_page(
212213
__name__,
213214
path='/historical',
214215
redirect_from=['/historical-analysis', '/historical-outlook']
@@ -232,8 +233,8 @@ However, this can be customized by creating a file called `not_found_404.py`
232233

233234
You can also pass `layout=` directly into `register_page`. Here's a quick multi-page app written in a single file:
234235
```
235-
app.register_page('historical_analysis', path='/historical-analysis', layout=html.Div(['Historical Analysis Page'])
236-
app.register_page('forecast', path='/forecast', layout=html.Div(['Forecast Page'])
236+
dl.plugins.register_page('historical_analysis', path='/historical-analysis', layout=html.Div(['Historical Analysis Page'])
237+
dl.plugins.register_page('forecast', path='/forecast', layout=html.Div(['Forecast Page'])
237238
238239
app.layout = dbc.Container([
239240
dbc.NavbarSimple([
@@ -251,13 +252,14 @@ However, we recommend splitting out the page layouts into their own files in `pa
251252
It's possible to pass query strings from the url to a layout function.
252253
For example:
253254
```python
254-
import dash
255+
from dash import dcc, html
256+
from dash_labs.plugins import register_page
255257

256-
dash.register_page(__name__, path='/dashboard')
258+
register_page(__name__, path='/dashboard')
257259

258260
def layout(velocity=0, **other_unknown_query_strings):
259-
return dash.html.Div([
260-
dash.dcc.Input(id='velocity', value=velocity)
261+
return html.Div([
262+
dcc.Input(id='velocity', value=velocity)
261263
])
262264

263265
```
@@ -266,7 +268,7 @@ def layout(velocity=0, **other_unknown_query_strings):
266268

267269
**Path Variable**
268270

269-
Another way to pass variables to the layout is to use the `path_template` parameter in `dash.register_page`. You can
271+
Another way to pass variables to the layout is to use the `path_template` parameter in `register_page`. You can
270272
define which segments of the path are variables by marking them like this: `<variable_name>`. The layout function then receives the `<variable_name>` as a keyword argument.
271273

272274

@@ -275,16 +277,17 @@ will receive `**{"asset_id": "a100"}`. Here is an example with two variables in
275277

276278

277279
```python
278-
import dash
280+
from dash import html
281+
from dash_labs.plugins import register_page
279282

280-
dash.register_page(
283+
register_page(
281284
__name__,
282285
path_template="/asset/<asset_id>/department/<dept_id>",
283286
)
284287

285288

286289
def layout(asset_id=None, dept_id=None, **other_unknown_query_strings):
287-
return dash.html.Div(f"variables from pathname: asset_id: {asset_id} dept_id: {dept_id}")
290+
return html.Div(f"variables from pathname: asset_id: {asset_id} dept_id: {dept_id}")
288291

289292
```
290293
![image](https://user-images.githubusercontent.com/72614349/146810311-73ab7f24-bb6d-4f4e-b3c5-257917d0180d.png)
@@ -301,7 +304,7 @@ in `/demos/multi_page_long_callback`.
301304

302305
## Reference
303306

304-
**`dash.register_page`**
307+
**`dl.plugins.register_page`**
305308

306309
```python
307310
def register_page(
@@ -414,7 +417,7 @@ OrderedDict([
414417
order=1,
415418

416419
supplied_layout=None,
417-
layout=<function pages.historical_outlook.layout>,
420+
layout=`<function pages.historical_outlook.layout>`,
418421

419422
custom_key='custom value'
420423
)

docs/09-MultiPageDashApp-NestedFolders.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
> ## Status: Multi-Page Dash App Plugin
3-
> #### Under active development: A plugin to simplify creating multi-page Dash apps. This is a preview of functionality that will be added to Dash 2.x.
3+
> #### The `pages` functionality is now part of dash 2.5! These docs remain here for legacy purposes. `pages` is a plugin to simplify creating multi-page Dash apps.
44
> **[See the community announcement for details and discussion](https://community.plotly.com/t/introducing-dash-pages-dash-2-1-feature-preview/57775)**
55
66

@@ -12,7 +12,7 @@
1212
If you would like to add an example, feel free to create a pull request!
1313

1414
### Example: Nested Folders
15-
This example shows how `dash.register_page` handles
15+
This example shows how `dl.plugins.register_page` handles
1616
- Using Nested folders in `pages/`
1717
- Storing icons as arbitrary keyword arguments
1818

@@ -126,14 +126,14 @@ if __name__ == "__main__":
126126

127127
```
128128

129-
Recall from the previous chapter that `dash.register_page` also accepts arbitrary keyword arguments. We use this
129+
Recall from the previous chapter that `dl.plugins.register_page` also accepts arbitrary keyword arguments. We use this
130130
feature to store the icon used in the nav for each page.
131131

132132
Here is how we store the FontAwesome icon for `pages/chapter/pie-chart.py`
133133

134134
```python
135135

136-
dash.register_page(__name__, icon="fas fa-chart-pie")
136+
dl.plugins.register_page(__name__, icon="fas fa-chart-pie")
137137
```
138138

139139
You can see how the icon is included in the sidebar navigation:

docs/10-MultiPageDashApp-MetaTags.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

2+
23
> ## Status: Multi-Page Dash App Plugin
3-
> #### Under active development: A plugin to simplify creating multi-page Dash apps. This is a preview of functionality that will be added to Dash 2.x.
4+
> #### The `pages` functionality is now part of dash 2.5! These docs remain here for legacy purposes. `pages` is a plugin to simplify creating multi-page Dash apps.
45
> **[See the community announcement for details and discussion](https://community.plotly.com/t/introducing-dash-pages-dash-2-1-feature-preview/57775)**
56
67

@@ -52,9 +53,9 @@ In the `pages` folder we have 3 simple pages to demonstrate this feature.
5253

5354
#### `a_page.py`
5455
```python
55-
import dash
56+
from dash_labs.plugins import register_page
5657

57-
dash.register_page(__name__)
58+
register_page(__name__)
5859

5960

6061
def layout():
@@ -69,9 +70,9 @@ def layout():
6970

7071
#### `birds.py`
7172
```python
72-
import dash
73+
from dash_labs.plugins import register_page
7374

74-
dash.register_page(
75+
register_page(
7576
__name__,
7677
title="(birds) The title, headline or name of the page",
7778
description="(birds) A short description or summary 2-3 sentences",
@@ -87,10 +88,11 @@ def layout():
8788

8889
#### `home.py`
8990
```python
90-
import dash
91+
9192
from dash import html
93+
from dash_labs.plugins import register_page
9294

93-
dash.register_page(
95+
register_page(
9496
__name__,
9597
path="/",
9698
image="birdhouse.jpeg",

docs/11-MultiPageDashApp-LayoutFunctions.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
> ## Status: Multi-Page Dash App Plugin
3-
> #### Under active development: A plugin to simplify creating multi-page Dash apps. This is a preview of functionality that will be added to Dash 2.x.
3+
> #### The `pages` functionality is now part of dash 2.5! These docs remain here for legacy purposes. `pages` is a plugin to simplify creating multi-page Dash apps.
44
> **[See the community announcement for details and discussion](https://community.plotly.com/t/introducing-dash-pages-dash-2-1-feature-preview/57775)**
55
66

@@ -79,9 +79,9 @@ This is the `home.py` file. (The `about.py` and `topic_1.py` files are similar).
7979

8080
```python
8181
from dash import html
82-
import dash
82+
from dash_labs.plugins import register_page
8383

84-
dash.register_page(__name__, top_nav=True)
84+
register_page(__name__, top_nav=True)
8585

8686

8787
layout = html.Div("About page content")
@@ -125,18 +125,19 @@ def sidebar():
125125
```
126126
Here is `topic_2.py` (`topic_1.py` and `topic_3.py` are similar). Note that the layout is also a function.
127127

128-
As you see below, `topic_2.py` and `topic_3.py` will NOT have `top_nav=True` included in `dash.register_page`,
128+
As you see below, `topic_2.py` and `topic_3.py` will NOT have `top_nav=True` included in `register_page`,
129129
but `topic_1.py` will include `top_nav=True` because we want that page in the navbar.
130130

131131
```python
132132
from dash import html
133133

134-
import dash
134+
135135
import dash_bootstrap_components as dbc
136136

137137
from .side_bar import sidebar
138+
from dash_labs.plugins import register_page
138139

139-
dash.register_page(__name__)
140+
register_page(__name__)
140141

141142

142143
def layout():
@@ -147,7 +148,7 @@ def layout():
147148
```
148149
The main purpose of this example is to show how to use `dash.page_registry` from within the `pages` folder.
149150
The reason `sidebar` and the layouts for the three topic pages need to be functions is that pages are added to
150-
`dash.register_page`as each module is imported from the `pages` folder and `dash.register_page` is called.
151+
`register_page`as each module is imported from the `pages` folder and `register_page` is called.
151152
If you don't use a function then all the pages may not yet be in `dash.page_registry` when it's used to create thing
152153
like the sidebar. When you use a function, it will create the layout when it's used rather than when it's imported.
153154

docs/demos/multi_page_basics/app.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
app = Dash(__name__, plugins=[dl.plugins.pages])
66

7-
dash.register_page("another_home", layout=html.Div("We're home!"), path="/")
8-
dash.register_page(
7+
dl.plugins.register_page("another_home", layout=html.Div("We're home!"), path="/")
8+
dl.plugins.register_page(
99
"very_important", layout=html.Div("Don't miss it!"), path="/important", order=0
1010
)
1111

docs/demos/multi_page_basics/app_dbc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__name__, plugins=[dl.plugins.pages], external_stylesheets=[dbc.themes.BOOTSTRAP]
77
)
88

9-
dash.register_page("home", layout="We're home!", path="/")
9+
dl.plugins.register_page("home", layout="We're home!", path="/")
1010

1111
navbar = dbc.NavbarSimple(
1212
dbc.DropdownMenu(

docs/demos/multi_page_basics/app_ddk.py

-22
This file was deleted.

docs/demos/multi_page_basics/pages/historical_archive.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from dash import html, dcc, callback, Input, Output
1+
from dash import html
22

3-
import dash
3+
from dash_labs.plugins import register_page
44

5-
dash.register_page(__name__)
5+
register_page(__name__)
66

77

88
def layout():
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dash import html
2-
import dash
2+
from dash_labs.plugins import register_page
33

4-
dash.register_page(__name__, path="/404")
4+
register_page(__name__, path="/404")
55

66

77
layout = html.H1("Custom 404")

docs/demos/multi_page_basics/pages/outlook.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import dash
1+
from dash_labs.plugins import register_page
22

3-
dash.register_page(
3+
register_page(
44
__name__,
55
title="Forward Outlook",
66
description="This is the forward outlook", # should accept callable too

0 commit comments

Comments
 (0)