📣 Introducing Dash `/pages` - A Dash 2.x Feature Preview

:mega: dash-labs V1.0.8 is now available

I’m pleased to announce some new features and bug fixes for the pages plug-in available in dash-labs 1.0.6.

:new: property: image_url

The pages plug-in automatically creates the meta-tags which describe a page’s content when you share a link on social media. If you would like to include an image, you can now either use an image file from the assets folder, or a link to an image using the image_url property. This is handy if you would like to host your images on a third party site or CDN.

dash.register_page(__name__, image_url="https//site.com/path/to/myimage.png")

If no image_url is provided, it will search the assets folder for an image as previously described in the documentation.

Thanks to @raptorbrad for the contribution! :medal_sports:

:new: dash_labs.print_registry()

When debugging a pages app, it’s very helpful to inspect the content of the dash.page_registry. If you simply
print(dash.page_registry) it can include a lot of data that’s hard to read.

print_registry() is a handy utility that pretty prints all or part of the dash.page_registry dict.

Examples for print_registry()

from dash import Dash, html
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="/")

dl.print_registry()

Will print to the console:

{'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': 0,
                  'supplied_order': None,
                  'supplied_layout': Div("We're home!"),
                  'image': None,
                  'supplied_image': None,
                  'image_url': None,
                  'redirect_from': None,
                  'layout': Div("We're home!")}}

print_registry(modules='ALL', exclude=None, include='ALL')

Params:

  • module: (string or list) Default “ALL”. Specifies which modules to print.
  • exclude: (string or list) Default None. Specifies which of the page’s parameter(s) to exclude.
  • include: (string or list) Default “ALL”. Prints only the parameters that are specified.

Examples:

  • print_registry() Will print the entire content of dash.page_registry
  • print_registry("pages.home") will print only one module
  • print_registry(__name__) will print the current module. When called from app.py it will print all modules. If called from a file in the pages folder dash.page_registry may not be complete.
  • print_registry(["pages.home", "pages.archive"]) Will print 2 modules
  • print_registry(exclude="layout") will print info for all the modules, but will exclude the page[“layout”]
  • print_registry(include=["path", "name"] will print only the page[“path”] and page[“name”] for all modules
  • `print_registry(include=None) prints the keys (module names) only

:beetle: Bug fixes:

  • Fixed a UTF-8 error when opening files - thanks for reporting @adamschroeder
  • Fixed a bug in the meta tags. Now when sharing links on Twitter, the card is formatted correctly, includes an image(if any) and the link to the page works. Thanks for reporting and for the PR to fix it @raptorbrad
5 Likes