Populating a Dash data_table column with switches

Viewed 18

Is it possible to populate the column Toggle with ‘mantine’ switches?

I am using the code from the docs that show how to populate a column with dropdowns, but I cannot figure out how to get any further than this.

import dash, dash_table
import dash_html_components as html
import dash_mantine_components as dmc
import pandas as pd

app = dash.Dash(__name__)

df = pd.DataFrame({
    'A': [1, 2],
    'B': [4, 5],
    'C': [7, 8]
})

def toggle_switch():
    return dmc.Switch(
    size="lg",
    radius="sm",
    label="Enable this option",
    checked=True
)

app.layout = html.Div([
    dash_table.DataTable(
        id='datatable',
        columns=[
            {"name": i, "id": i} for i in df.columns
        ] + [{"name": "Toggle", "id": "toggle"}],
        data=df.to_dict('records'),
        editable=True,
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
0 Answers
Related