Related to a Circular Dependency question
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.
When I use a circular reference in the same callback it works but I get two errors
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,debounce=True)
@callback (
Output('location', 'hash'),
Output('input', 'value'),
Input('location', 'hash'),
Input('input', 'value'),
)
def update_input(hash: str, input: str):
if input is None: input = hash.lstrip('#')
else: hash = '#' + input
return hash, input
The Id not found in layout error can be suppressed but is it advisable?
If set_props is used instead of Output there is no error:
@callback (
Output('input', 'value'),
Input('location', 'hash'),
Input('input', 'value'),
)
def update_input(hash: str, input: str):
if input is None: input = hash.lstrip('#')
else: hash = '#' + input
set_props('location', {'hash': hash})
return input



