API Reference
Creating and interacting with the Mito Spreadsheet component in Dash.
The Spreadsheet Component
To display a Mito spreadsheet in a Dash application, use the following code:
from mitosheet.mito_dash.v1 import Spreadsheet, activate_mito
from dash import Dash, html
import pandas as pd
app = Dash(__name__)
activate_mito(app)
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv')
app.layout = html.Div([
html.H1('Empty Mito Spreadsheet'),
Spreadsheet(df, id={'type': 'spreadsheet', 'id': 'sheet'})
])
if __name__ == '__main__':
app.run_server(debug=True)Activate Mito
After creating a Dash app instance, you need to activate Mito. This activation step simply sets up communication between the Mito frontend and the backend, and ensures that Mito works like a proper spreadsheet.
Spreadsheet Component API
After you have activated Mito, you can now create a Spreadsheet component. It has the following API:
*args
Pass any number of Pandas dataframes or paths to CSV files that will be displayed by in the Mito spreadsheet.
id
An necessary key that uniquely identifies this component as a spreadsheet with a unique ID. Must be a dictonary the the keys type and id, where type: spreadsheet and id is a unique string.
import_folder
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. See more here.
df_names
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
Pass functions that are available as spreadsheet functions in the Mito spreadsheet. See more here. (Mito Enterprise)
editors
Pass Python functions that edit a dataframe to get an auto-generated Ui. See more here. (Mito Enterprise)
code_options
Pass a CodeOptions object to specify how the code should be generated. See more here. (Mito Enterprise)
track_selection
If you want to register callbacks based on selection changes in the sheet, set this to True. Has a performance impact on scrolling through your data.
Callback Props and Types
Like any other Dash component, the Spreadsheet component allows you to make your Dash app interactive by registering callback functions. However, to give you a better callback experience, Mito works slighly differently than default dash callbacks.
A simple interactive example
Mito works differently in that it requires you to use the @mito_callback decorator when you're subscribing to Input or State changes from a Mito spreadsheet.
A simple example:
How is @mito_callback different?
Only two valid
propsyou can subscribe to for the Mito component are:spreadsheet_result: returns theSpreadsheetResultclass defined below.spreadsheet_selection: returns the data that is currently selected in the Mito spreadsheet.
Both of these properties do not return JSON that you need to parse. Rather, they return the actual objects you want to use - resulting in a much better developer experience than having to parse various types of JSON.
The SpreadsheetResult object
SpreadsheetResult objectThe SpreadsheetResult object gives you access to:
dfs: The dataframes generated by the analysiscode: The code generated by the analysisselection: The currently selected cells in the mitosheetanalysis: ARunnableAnalysisobject to help rerun the analysis on new data. To learn more, see the RunnableAnalysis documentation.
Examples
Below are examples of common uses of the Mito spreadsheet component in a Dash application.
Empty Mito Spreadsheet
Display a Dataframe for Editing
Display a CSV file for Editing
Displaying Mito generated code
Last updated
Was this helpful?