> For the complete documentation index, see [llms.txt](https://docs.trymito.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trymito.io/mito-for-dash/common-design-patterns/change-sheet-data-from-a-select.md).

# Change Sheet Data from a Select

## Motivation

1. You have a dropdown that allows users to select a specific dataset.&#x20;
2. You want to then automatically load this data directly into the Mito spreadsheet.

To do so, you simply need to write to the `data` parameter of the Mito spreadsheet.&#x20;

## 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 based on a select

```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("Stock Analysis", style={'color': 'white'}),
    # A dropdown for selecting between two dataframes
    dcc.Dropdown(
        id='dropdown',
        options=[
            {'label': 'Stock Data', 'value': 'stock_data'},
            {'label': 'Stock Data 2', 'value': 'stock_data_2'},
        ],
        value='stock_data'
    ),
    Spreadsheet(id={'type': 'spreadsheet', 'id': 'sheet'}),
])

@callback(
    Output({'type': 'spreadsheet', 'id': 'sheet'}, 'data'),
    Input('dropdown', 'value')
)
def update_spreadsheet_data(dropdown_value):
    if dropdown_value == 'stock_data':
        df = pd.DataFrame({'First Data': [1, 2, 3], 'Second Data': [4, 5, 6]})
    else:
        df = pd.DataFrame({'First Data': [7, 8, 9], 'Second Data': [10, 11, 12]})

    return df.to_dict('records')

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.trymito.io/mito-for-dash/common-design-patterns/change-sheet-data-from-a-select.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
