I don’t seem to be able to edit data in my DataTable. Dash version 2.2.0. Any ideas what I’m doing wrong?
dataTable = dash_table.DataTable(id="dataTable1", data=df.to_dict('records'), page_size=10, editable=True)
Here’s the full code:
# Import libraries
from dash import Dash, dash_table
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import pandas as pd
import plotly.express as px
from dash.exceptions import PreventUpdate
# Import data into Pandas dataframe
df = px.data.gapminder()
# Filter data with a list of countries we're interested in exploring
country_list = ['Canada', 'Brazil', 'Norway', 'Germany']
df = df[df['country'].isin(country_list)]
# Create a Dash DataTable, limit the page size to 10 because this data set is huge
dataTable = dash_table.DataTable(id="dataTable1", data=df.to_dict('records'), page_size=10, editable=True)
# Create a line graph of life expectancy over time
fig = px.line(df, x= 'year', y = 'lifeExp', color = 'country', markers=True)
graph1 = dcc.Graph(id='figure1', figure=fig)
# Create the Dash application with Bootstrap CSS stylesheet
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
# Create the app layout
app.layout = dbc.Container(
dbc.Row([
dbc.Col([
graph1,
dataTable
])
])
)
@app.callback(
Output('figure1', 'figure'),
Input('dataTable1', 'data')
)
def display_output(data):
print("data changed")
raise PreventUpdate
# print(str(data))
# df = pd.DataFrame(rows, columns=[c['name'] for c in columns])
# return {
# 'data': [{
# 'dimensions': [{
# 'label': col['name'],
# 'values': df[col['id']]
# } for col in columns]
# }]
# }
# Launch the app server
if __name__ == '__main__':
app.run_server()