Mito
Search
K

API Reference

The Spreadsheet Component

To display the Mito spreadsheet in a Streamlit application, use the following code:
from mitosheet.streamlit.v1 import spreadsheet
# ... rest of your streamlit app
spreadsheet()

Component API

from mitosheet.streamlit.v1 import spreadsheet
spreadsheet(
*args: ,
import_folder: Optional[str]=None,
df_names: Optional[List[str]]=None,
sheet_functions: Optional[List[Callable]]=None,
importers: Optional[List[Callable]]=None,
key=None
) -> Tuple[Dict[str, pd.DataFrame], str]
Argument Name
Type
Explanation
*args
Union[pd.DataFrame, str]
Pass any number of Pandas dataframes or paths to CSV files that will be displayed by in the Mito spreadsheet.
import_folder
Optional[str]
A file path to a folder where users can import data from. Any subfolders will be available for navigation and importing within the Mito file browser.
df_names
Optional[List[str]]
if you pass Pandas dataframes through the args, then optionally include the names of these dataframes in this list. This makes Mito generated code more correct.
sheet_functions
Optional[List[Callable]]
Pass functions that are available as spreadsheet functions in the Mito spreadsheet. This is a Mito Enterprise feature.
importers
Optional[List[Callable]]
Pass custom data importers that get an auto-generated UI. This is a Mito Enterprise feature.
key
Optional[str]
An optional key that uniquely identifies this component. Necessary if you have multiple Mito spreadsheet displaying the same data.

Return Types

The spreadsheet component returns:
new_dfs, code = spreadsheet()
  • new_dfs: a Python dictionary from dataframe name to dataframe object. There will be one entry for each tab in the Mito spreadsheet.
  • code: a string that corresponds to the edits made by the user of the course of the Mito analysis.

Examples

Below are examples of common uses of the Mito spreadsheet component in a streamlit application.

Empty Mito Spreadsheet

from mitosheet.streamlit.v1 import spreadsheet
# Render an empty spreadsheet that allows users to import from the ./data folder
new_dfs, _ = spreadsheet(import_folder='./data')

Display a Dataframe for Editing

import pandas as pd
from mitosheet.streamlit.v1 import spreadsheet
# Pass a single dataframe for editing
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
new_dfs, _ = spreadsheet(df, df_names=['df'])
new_df = list(new_dfs.values())[0]
# Note that multiple dataframes can be passed as well
# and each will appear as a tab in the Mito spreadsheet
new_dfs, _ = spreadsheet(df1, df2, df_names=['df1', 'df2'])

Display a CSV file for Editing

from mitosheet.streamlit.v1 import spreadsheet
# Mito will automatically read this file into a dataframe
# and display it as a sheet tab
dfs, _ = spreadsheet('path-to-file.csv')

Displaying Mito generated code

from mitosheet.streamlit.v1 import spreadsheet
# The second return value is Mito generated code
new_dfs, code = spreadsheet('path-to-file.csv')
# Display the code
st.code(code)