Search code examples
pythoncallbackplotly-dashdashboard

How to access the input value in the app layout in python Dash?


I have the following component in my app.layout:

app.layout = html.Div(
    [html.Tr([html.A(html.Td(id='processed_input1'), href="https://www.example.com/" + str(processed_input1))])

@app.callback(
    Output('processed_input1', 'children'),
    Output('processed_input2', 'children'),
    Input("input1", "value"),
    Input("input2", "value")
)
def callback_api(input1, input2):
    do something
    return processed_input1, processed_input2

Everything works fine, but I need a way to access the value of the 'processed_input1' key and convert it to python string in order to concatenate it to my URL. Dash seems only to accept the outputs from the callbacks to be part of some dcc or html components, but what if I just need the output as python string so I can attach it to my url?

Thanks!


Solution

  • I realized that you can add a string to the children of any python dash component, so I can use that trick to create first the code for app-layout in the callback-function, put the values as children and then return it for the wrapper component in the app-layout.