Multi-Page Apps - manually configuring layout function for use with query strings

I’m trying to use Dash Multi-Page Apps (great stuff!) with query strings. The problem I have is that the generated page needs data that is loaded during the application start. I’m wondering what is the best way to have the layout function with the loaded data available(e.g. as class properties), and then use it with the dash.page_container.

The example here shows only this way of declaring the layout function for the page when using query strings:

import dash
from dash import html

dash.register_page(__name__)

def layout(report_id=None, **other_unknown_query_strings):
    return html.Div(
	children=[
	    html.H1(children='This is our Archive page'),

	    html.Div(children=f'''
	        This is report: {report_id}.
	    '''),

	])

where I need to be able something more like:

page_obj = Page1(data1, data2)
dash.page_container.add_page(page_obj.layout, name..)

Hello @kiteme,

Instead of trying to do it with pages and the layout, you can store it on initialization in dictionaries.

So, something like this:

customloads ={}

def layout(query=None):
     if query:
          if query in customloads:
              return customloads[query]
          else
              #rest of loading

customloads[query1] = layout(query1)
customloads[query2] = layout(query2)

I managed to find how to do this using the pages:

dash.register_page('pages.layout', name="Main Page", path="", layout=layout.layout)

where layout=layout.layout points to the layout function

1 Like

As long as it works. :grin: