Circular Dependency

I want that when a page loads, the hash value in the url (http://localhost:8050/#some_text) to be inserted in an input field. And when the input field is changed, it updates the hash value.

This is my trial in multipage

app.py:

from dash import dcc, page_container, html, Dash

app = Dash(
   __name__,
   use_pages=True,
)

location = dcc.Location(id='location', refresh=False)
app.layout = [location, page_container]

if __name__ == '__main__':
   app.run(debug=True)

home.py:

from dash import callback, Output, Input, register_page, dcc

register_page(__name__, name='home', path='/')

layout = dcc.Input(id='input',autoFocus=True)

@callback (
   Output('input', 'value'),
   Input('location', 'hash'),
)
def update_input(hash: str):
   return hash.lstrip('#')

@callback (
   Output('location', 'hash'),
   Input('input', 'value'),
   prevent_initial_call = True,
)
def update_hash(input):
   return '#' + input

But obviously there is a circular reference problem. How to implement it?

Hi @clodoaldo

You can do circular updates, but they must be in the same callback.

More in the docs here:

2 Likes