Comment on page
Custom Editors: Autogenerate UI from Any Function
Extend Mito with custom dataframe transformations, like proprietary algorithms, calculations, and domain-specific knowledge.
This is a Mito Enterprise feature. Upgrade to extend your spreadsheet with additional functionality.
The Mito spreadsheet is built to be extensible for your team's use case. Mito users or infrastructure administrators can extend Mito with custom dataframe editing capabilities, like proprietary algorithms, calculations, and domain-specific knowledge.
Stop your internal Python code from rotting on the shelf, and get it to end users in the most intuitive interface -- a spreadsheet.
Adding custom editing functionality to the Mito spreadsheet is very simple:
- 1.Define a Python function that takes a
pd.DataFrame
and returns apd.DataFrame
. - 2.Pass this function to the
editors
parameter when creating the Mito sheet. - 3.Use the
Custom Edits
dropdown in the Mito sheet to access this functionality - with an auto-generated UI!
Imagine we're a financial institution that has implemented the following Python function, and we want to expose it to our users:
import pandas as pd
def calculate_moving_average(df, column_to_average, window_size, exponential=False):
"""
Calculate moving average for a given financial time series data.
"""
if exponential:
df['EMA'] = df[column_to_average].ewm(span=window_size, adjust=False).mean()
else:
df['SMA'] = df[column_to_average].rolling(window=window_size).mean()
return df
First, we must add types to the parameters of the function. This ensures that Mito can correctly generate a UI for each of these parameters. In this case, we type this function in the following way:
import pandas as pd
from mitosheet.extensions.v1 import ColumnHeader
def calculate_moving_average(df: pd.DataFrame, column_to_average: ColumnHeader, window_size: int, exponential: bool=False):
"""
Calculate moving average for a given financial time series data.
"""
if exponential:
df['EMA'] = df[column_to_average].ewm(span=window_size, adjust=False).mean()
else:
df['SMA'] = df[column_to_average].rolling(window=window_size).mean()
return df
Then, pass this function to the
editors
parameter. Jupyter
Streamlit
Dash
Pass this custom editor with:
mitosheet.sheet(editors=[calculate_moving_average])
Pass this custom editor with:
spreadsheet(editors=[calculate_moving_average])
Pass this custom editor with:
Spreadsheet(editors=[calculate_moving_average])
Pass the following data to the Mito spreadsheet, so that we can test our new custom editor:
import pandas as pd
data = {'Date': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05'],
'Price': [100, 102, 105, 101, 98]}
df1 = pd.DataFrame(data)
In the toolbar, a
Custom Edits
tab option will appear, with the Calculate Moving Average function beneath it:
Selecting this option will open a taskpane that allows you to configure this function, and calculate the moving average!

To see all the valid parameter types, check out the Supported Types section of the custom importers page.