Repository: mito-ds/mito

Issue:
Global Dataframe State Bug in Dash
Sorry I don't have time currently to create a minimal example. But see example here: https://drive.google.com/file/d/1xiJIKLmCTpeEhf_lt5fd-UmXuJViubzZ/view?usp=sharing

We should test if the same thing happens in Streamlit. 

In addition, you can see a temporary fix here: https://github.com/plotly/mito-dash-application/pull/2/commits/cdbdceeae5a93a6581cdc55fd360300305a9cd93


Discussion:
We just need to make a copy of the dataframes before passing them to the spreadsheet result. Nice catch here. I think df.copy() is a fine soulution for now.

Resolving patch:
diff --git a/mitosheet/dash_app.py b/mitosheet/dash_app.py
--- a/mitosheet/dash_app.py
+++ b/mitosheet/dash_app.py
@@ -1,40 +1,24 @@
-from dash import Dash, callback, Input, Output, html, dash_table
-from mitosheet.mito_dash.v1 import Spreadsheet, mito_callback
+from dash import Dash, Input, Output, html
+from mitosheet.mito_dash.v1 import Spreadsheet, mito_callback, activate_mito
 
 app = Dash(__name__)
+activate_mito(app)
 
-CSV_URL = '/Users/marthacryan/gitrepos/mito/mitosheet/datasets/small-datasets/loans.csv'
+CSV_URL = 'https://raw.githubusercontent.com/plotly/datasets/master/tesla-stock-price.csv'
 
 app.layout = html.Div([
     html.H1("Stock Analysis"),
-    Spreadsheet(import_folder='datasets', id='sheet'),
-    html.Div(id='output'),
-    html.Button('Run', id='rerun-analysis'),
-    html.Div(id='output-run-analysis')
+    Spreadsheet(CSV_URL, id={'type': 'spreadsheet', 'id': 'sheet'}),
+    html.Div(id='output')
 ])
 
 @mito_callback(
     Output('output', 'children'),
-    Input('sheet', 'spreadsheet_result'),
+    Input({'type': 'spreadsheet', 'id': 'sheet'}, 'spreadsheet_result'),
 )
 def update_code(spreadsheet_result):
     return html.Div([
-        html.Code(spreadsheet_result.analysis().fully_parameterized_function),
-    ])
-
-@mito_callback(
-    Output('output-run-analysis', 'children'),
-    Input('rerun-analysis', 'n_clicks'),
-    Input('sheet', 'spreadsheet_result'),
-    prevent_initial_call=True
-)
-def update_output(n_clicks, spreadsheet_result):
-    result = spreadsheet_result.analysis().run()
-    if result is None:
-        return None
-    return html.Div([
-        html.H3('Analysis Result'),
-        dash_table.DataTable(result.to_dict('records'), [{"name": i, "id": i} for i in result.columns])
+        html.Code(spreadsheet_result.code())
     ])
     
 if __name__ == '__main__':
diff --git a/mitosheet/mitosheet/mito_dash/v1/spreadsheet.py b/mitosheet/mitosheet/mito_dash/v1/spreadsheet.py
--- a/mitosheet/mitosheet/mito_dash/v1/spreadsheet.py
+++ b/mitosheet/mitosheet/mito_dash/v1/spreadsheet.py
@@ -298,7 +298,7 @@ def get_all_json(self) -> str:
         
         def get_result(self):
             return SpreadsheetResult(
-                dfs=self.mito_backend.steps_manager.dfs,
+                dfs=(df.copy() for df in self.mito_backend.steps_manager.dfs),
                 code=self.mito_backend.steps_manager.code(),
                 index_and_selections=self.index_and_selections,
                 fully_parameterized_function=self.mito_backend.fully_parameterized_function,


Test patch: