# Refresh Sheet Data Periodically

## Motivation

If the data you are displaying in the spreadsheet changes over time, you can update what is displayed in the sheet. Simply write to the `data` parameter of the Mito spreadsheet.

## Valid types for `data`

The **`data`** parameter should be a list of dicts with strings as keys and values of type string, number, or boolean.  For example, valid data might be:

```python
# Passing the data
[
    {'Column 1': 1, 'Column 2': 4}, 
    {'Column 1': 2, 'Column 2': 5}, 
    {'Column 1': 3, 'Column 2': 6}
]
# Results in Mito displaying the dataframe
df = pd.DataFrame({'Column 1': [1, 2, 3], 'Column 2': [4, 5, 6]})
```

You can go from Pandas dataframe to `data` format with the following code:

```python
df = pd.DataFrame({'Column 1': [1, 2, 3], 'Column 2': [4, 5, 6]})

df.to_dict('records') # Returns data in the correct format.
```

*Note that Mito aims to accept the same `data` input as the* [*Dash Data Table*](https://dash.plotly.com/datatable/reference)*.*

## Examples

#### Change the data in the Mito spreadsheet on a time interval

```python
from dash import Dash, callback, Input, Output, html, dcc
from mitosheet.mito_dash.v1 import Spreadsheet, mito_callback, activate_mito
import pandas as pd

app = Dash(__name__)
activate_mito(app)

app.layout = html.Div([
    html.H1("Data Changer", style={'color': 'white'}),
    dcc.Interval(id='interval1', interval=5 * 1000, n_intervals=0),
    Spreadsheet(id={'type': 'spreadsheet', 'id': 'sheet'}),
])

@callback(
    Output({'type': 'spreadsheet', 'id': 'sheet'}, 'data'),
    Input('interval1', 'n_intervals')
)
def update_spreadsheet_data(n_intervals):
    # Get new df data here
    df = pd.DataFrame({'First Data': [1, 2, 3], 'Second Data': [4, 5, 6]})
    return df.to_dict('records')

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