Change value using dropdown

How do I dynamically change a full sentence in a Dash app based on the selected value from a dropdown, not just a part of the sentence? but i change sentence every time


app.layout = dbc.Container([

            html.H2([
                'ski Resorts in ',
                html.Span(id="title",children='',style={'font-weight':'bold'}),
                "                  with peaks above elevation M"
            ],style={"text-align":'center'}),
            html.P("Select Options Below: "),
            dcc.Dropdown(
                id="country-dropdown",
                options=ski_resorts["Country"].unique(),
                value="Andorra",
                className="dbc"

            )

])
@app.callback(
    Output("title","children"),
    Input("country-dropdown","value")
)
def hello_world(country):
    print(country)
    print(len(country))
    print(type(country))

    return country


if __name__ == "__main__":
    app.run(debug=True, port=8334)```

Like this?

from dash import Dash, html, dcc, Input, Output
import dash_bootstrap_components as dbc

app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container([

            html.H2(
                id="title",
                children="Default Header",
                style={"text-align":'center'}
            ),
            html.P("Select Options Below: "),
            dcc.Dropdown(
                id="country-dropdown",
                options=["France", "Spain", "Denmark"],
                value="France",

            )

])
@app.callback(
    Output("title","children"),
    Input("country-dropdown","value"),
    prevent_initial_call=True
)
def hello_world(country):

    new_header = {
        "France": "Header info 0",
        "Spain": "Header info 1",
        "Denmark": "Header info 2"
    }[country]

    return new_header

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

Maybe interesting:

2 Likes