# Update a DataTable by creating a dataframe in a callback function

**URL:** https://community.plotly.com/t/update-a-datatable-by-creating-a-dataframe-in-a-callback-function/18929
**Category:** Dash Python
**Created:** [February 1, 2019, 11:59pm UTC](https://community.plotly.com/t/update-a-datatable-by-creating-a-dataframe-in-a-callback-function/18929 "2019-02-01T23:59:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sparrow](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sparrow](https://community.plotly.com/u/sparrow)
#### Post date: [February 1, 2019, 11:59pm UTC](https://community.plotly.com/t/update-a-datatable-by-creating-a-dataframe-in-a-callback-function/18929/1 "2019-02-01T23:59:36Z")

</div>

Hi, I’m trying to simply output a dataframe to a dash\_table from a callback function. If anyone can point me to an example of this I would appreciate it. I’ve looked through a lot of examples on the forum already but they solve the problem for “dash\_table\_experiments” which is different. Here is an example I cribbed from one of those topis which is not working.

Code:

import dash  
from dash.dependencies import Input, Output, State  
import dash\_html\_components as html  
import dash\_core\_components as dcc  
import dash\_table  
import pandas as pd

app = dash.Dash()

df = pd.DataFrame({‘x’: [‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’],‘y’: [4, 3, 1, 2, 3, 6],‘z’: [‘z’, ‘b’, ‘c’, ‘a’, ‘b’, ‘c’]})

app.layout = html.Div([  
dash\_table.DataTable(  
id=‘table’,  
columns=[{}],  
data={}  
),  
])

@app.callback(Output(‘table’, ‘data’))  
def update\_info\_table():  
columns=[{“name”: i, “id”: i} for i in df.columns]  
data=df.to\_dict(“rows”)  
return columns,data

if **name** == ‘ **main** ’:  
app.run\_server()

Error:  
TypeError: Unexpected keyword argument `rows`

---

<div class="post-metadata">

### Author: ![sparrow](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sparrow](https://community.plotly.com/u/sparrow)
#### Post date: [February 2, 2019, 6:03am UTC](https://community.plotly.com/t/update-a-datatable-by-creating-a-dataframe-in-a-callback-function/18929/2 "2019-02-02T06:03:27Z")

</div>

It looks like this one this one answers my question actually.

> [@How to pass Dataframe to dash Data-table through callbacks?](https://community.plotly.com/t/how-to-pass-dataframe-to-dash-data-table-through-callbacks/18494):
>
> Hi, why am I not able to pass a pandas data frame to a datatable in Dash data-table version 3.1.11 on the click of an html button? My code looks something like this ‘’’ app.layout = html.Div([html.Button(‘Server’, n\_clicks = 0, id=‘Server\_Button’), dash\_table.DataTable(id=‘datatable-upload-container’),]) @app.callback(Output(‘datatable-upload-container’, ‘data’), [Input(‘Server\_Button’, ‘n\_clicks’)]) def update\_output(clicks): if clicks%2!=0: df = pd.read\_csv(‘[https://raw.githubuser…](https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv)
