Use path in Input

I have an dcc Input looks like this:

id = 'first'


I want to get the current path in my app which is something like /path/page and use it for initializing the value in my input.

I tried this but doesnt seem to work.

@app.callback(dash.dependencies.Output('first', 'value'),
              [dash.dependencies.Input('url', 'pathname')])
def display_page(pathname):
    return get_value(pathname)

I don’t see anything immediately wrong with your code. Can you share a complete, simple, reproducable example?

Is the only way to get the path through a callback like the way above?

yes, during runtime, callbacks are the only way to get properties from components (in this case, path from Location)