[Python] Callback-triggered update of plotly figure following change in values of datatable in...

Discussão em 'Python' iniciado por Stack, Janeiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I have a map and datatable component in the layout that is update by a callback. The datatable is editable and the user can add new information to the new table. Upon the click event of update table

    I have two callbacks, one for updating the map and another one for datatable. What I'd like to do is run the map callback from inside of the datatable callback. Basically, I'd like to update the map based on the values of datatable.

    Can I run another callback from a callback or run some lines of code inside another callback? Trying to figure out a elegant and efficient way of doing this.

    layout = html.Div([

    # Plot map
    dcc.Graph(id="map-graph"),

    # DataTable
    dash_table.DataTable(

    id="table",

    columns=[{"id":"Type","name":"Type"},
    {"id":"space","name": "space"}],

    sort_action="native",
    filter_action="native",
    row_deletable=True
    ),

    # Update map
    dbc.Button("Update map", id="update-map", className="mr-1"),

    # Update Table
    dbc.Button("Update table", id="update-table", className="mr-1")


    ]),


    # Callbacks

    # Update map
    @app.callback(Output("map-graph", "figure"),
    [Input("update-map", "value")])
    def updatemap(value):

    ...
    do something
    ...

    return value


    # Update table
    @app.callback(Output("table", "data"),
    [Input("update-table", "value")])
    def updatetable(value):

    ...
    do something
    ...

    # Run the code inside previous callback which updates the map.

    return rows

    Continue reading...

Compartilhe esta Página