plotly / dash-labs

Work-in-progress technical previews of potential future Dash features.
MIT License
139 stars 39 forks source link

Added print_registry() #96

Closed AnnMarieW closed 2 years ago

AnnMarieW commented 2 years ago

Handy debugging tool and pretty printer for dash.page_registry.

Note that if print_registry() is called from a file in the pages folder, the dash.page_registry may not be complete.

:param modules: (string or list) Default "ALL". Specifies which modules to print. :param exclude: (string or list) Default None. Specifies which of the page's parameter(s) to exclude. :param include: (string or list) Default "ALL". Prints only the parameters that are specified.

Examples:


Here's an example of print_registry()

from dash import Dash, html, dcc
import dash
import dash_labs as dl

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

dash.register_page("another_home", layout=html.Div("We're home!"), path="/")
dash.register_page(
    "very_important", layout=html.Div("Don't miss it!"), path="/important", order=0
)

dl.print_registry()

...

Here is a partial output:

Dash is running on http://127.0.0.1:8050/

 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
**Note** When printing from a file in the pages folder, `dash_page_registry` may not be complete.  See the "Print page_registry" docs for more info.
{'very_important': {'module': 'very_important',
                    'supplied_path': '/important',
                    'path_template': None,
                    'path': '/important',
                    'supplied_name': None,
                    'name': 'Very important',
                    'supplied_title': None,
                    'title': 'Very important',
                    'description': '',
                    'order': 0,
                    'supplied_order': 0,
                    'supplied_layout': Div("Don't miss it!"),
                    'image': 'app.jpeg',
                    'supplied_image': None,
                    'redirect_from': None,
                    'layout': Div("Don't miss it!")},
 'another_home': {'module': 'another_home',
                  'supplied_path': '/',
                  'path_template': None,
                  'path': '/',
                  'supplied_name': None,
                  'name': 'Another home',
                  'supplied_title': None,
                  'title': 'Another home',
                  'description': '',
                  'order': None,
                  'supplied_order': None,
                  'supplied_layout': Div("We're home!"),
                  'image': 'app.jpeg',
                  'supplied_image': None,
                  'redirect_from': None,
                  'layout': Div("We're home!")},
 'pages.historical_archive': {'module': 'pages.historical_archive',

Here is an example with pathnames only:

`print_registry(include="path")'


**Note** When printing from a file in the pages folder, `dash_page_registry` may not be complete.  See the "Print page_registry" docs for more info.
{'very_important': {'path': '/important'},
 'another_home': {'path': '/'},
 'pages.historical_archive': {'path': '/historical-archive'},
 'pages.not_found_404': {'path': '/404'},
 'pages.outlook': {'path': '/forward-outlook'},
 'pages.path_variables': {'path': '/asset/inventory/department/branch-1001'},
 'pages.query_string': {'path': '/dashboard'},
 'pages.redirect': {'path': '/redirect'}}