# Callback through multipage

**URL:** <https://community.plotly.com/t/callback-through-multipage/40261>\
**Category:** Dash Python\
**Created:** [May 29, 2020, 12:59pm UTC](https://community.plotly.com/t/callback-through-multipage/40261 "2020-05-29T12:59:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![billbokay](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@billbokay](https://community.plotly.com/u/billbokay)\
**Post date:** [May 29, 2020, 12:59pm UTC](https://community.plotly.com/t/callback-through-multipage/40261/1 "2020-05-29T12:59:28Z")

</div>

Hi,

I would like to code a multipage app, using this documentation [URL Routing and Multiple Apps | Dash for Python Documentation | Plotly](https://dash.plotly.com/urls) with the second example presented. What I try to do is to set a value in the first page, and use it in the second page. I have tried to store it like in the “Example 1” of this documentation [Part 5. Sharing Data Between Callbacks | Dash for Python Documentation | Plotly](https://dash.plotly.com/sharing-data-between-callbacks) , as a hidden div. But I can not manage to pass the callback to the second layout. What did I miss ? Is it possible with these simple ways ? Where can I find a quick example of a callback from a page updating an element from another page ?

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![jon\_peter](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jon\_peter](https://community.plotly.com/u/jon_peter)\
**Post date:** [May 29, 2020, 8:51pm UTC](https://community.plotly.com/t/callback-through-multipage/40261/2 "2020-05-29T20:51:37Z")

</div>

Hey there Bill,

What I would do personally is use dcc.Store in place of a hidden div and attach it to the app.layout that way, no matter what page the user is on, the contents of the div should be accessible.

I took the example you brought up just now and changed a few things it worked for me. Basically, I added a dcc.store component onto app.layout with the id “index\_input”, then I changed the callback for page1-content to include 2 outputs, the 2nd basically stores the value into the index\_input.

Lastly, I changed the output of the callback for page-2.content, to include the selection from page 1 and page 2, this shows that page 2, does in fact “know” what he user selected in page 1. To use that value, all you need to do is add an additional input to a callback in page 2 with index\_input to access this value.  
Hope this helps.

Jon

> import dash  
> import dash\_core\_components as dcc  
> import dash\_html\_components as html
> 
> app = dash.Dash( **name** , suppress\_callback\_exceptions=True)
> 
> app.layout = html.Div([  
> dcc.Location(id=‘url’, refresh=False),  
> html.Div(id=‘page-content’),  
> dcc.Store(id=‘index\_input’,storage\_type=‘session’)  
> ])
> 
> index\_page = html.Div([  
> dcc.Link(‘Go to Page 1’, href=‘/page-1’),  
> html.Br(),  
> dcc.Link(‘Go to Page 2’, href=‘/page-2’),  
> ])
> 
> page\_1\_layout = html.Div([  
> html.H1(‘Page 1’),  
> dcc.Dropdown(  
> id=‘page-1-dropdown’,  
> options=[{‘label’: i, ‘value’: i} for i in [‘LA’, ‘NYC’, ‘MTL’]],  
> value=‘LA’  
> ),  
> html.Div(id=‘page-1-content’),  
> html.Br(),  
> dcc.Link(‘Go to Page 2’, href=‘/page-2’),  
> html.Br(),  
> dcc.Link(‘Go back to home’, href=‘/’),  
> ])
> 
> @app.callback([dash.dependencies.Output(‘page-1-content’, ‘children’),  
> dash.dependencies.Output(‘index\_input’,‘value’)],  
> [dash.dependencies.Input(‘page-1-dropdown’, ‘value’)])  
> def page\_1\_dropdown(value):  
> return ‘You have selected “{}”’.format(value),value
> 
> page\_2\_layout = html.Div([  
> html.H1(‘Page 2’),  
> dcc.RadioItems(  
> id=‘page-2-radios’,  
> options=[{‘label’: i, ‘value’: i} for i in [‘LA’, ‘NYC’, ‘MTL’]],  
> value=‘LA’  
> ),  
> html.Div(id=‘page-2-content’),  
> html.Br(),  
> dcc.Link(‘Go to Page 1’, href=‘/page-1’),  
> html.Br(),  
> dcc.Link(‘Go back to home’, href=‘/’)  
> ])
> 
> @app.callback(dash.dependencies.Output(‘page-2-content’, ‘children’),  
> [dash.dependencies.Input(‘page-2-radios’, ‘value’),  
> dash.dependencies.Input(‘index\_input’, ‘value’)])  
> def page\_2\_radios(value,p1\_input):  
> test = ‘You have selected’ + p1\_input + ‘in page1 and ’ + value + ’ in page 2’  
> return test
> 
> # Update the index
> 
> @app.callback(dash.dependencies.Output(‘page-content’, ‘children’),  
> [dash.dependencies.Input(‘url’, ‘pathname’)])  
> def display\_page(pathname):  
> if pathname == ‘/page-1’:  
> return page\_1\_layout  
> elif pathname == ‘/page-2’:  
> return page\_2\_layout  
> else:  
> return index\_page  
> # You could also return a 404 “URL not found” page here
> 
> if **name** == ‘ **main** ’:  
> app.run\_server(debug=True)

---

<div class="post-metadata">

**Author:** ![billbokay](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@billbokay](https://community.plotly.com/u/billbokay)\
**Post date:** [June 2, 2020, 10:29am UTC](https://community.plotly.com/t/callback-through-multipage/40261/3 "2020-06-02T10:29:43Z")

</div>

> [@jon\_peter](#):
>
> index\_input

Hi Jon,

Thank you very much, your idea is exactly what I was looking for and your example is of great help.

Thank you !
