Skip to content

Commit 4c57889

Browse files
author
Nate Rush
authored
Merge pull request #1247 from mito-ds/streamlit-height-config
mitosheet: make mito height into a variable
2 parents 62cf2a4 + 4eea626 commit 4c57889

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

mitosheet/css/mito.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
}
6262

6363
.mito-container {
64-
height: 538px;
64+
height: var(--mito-height);
6565
display: flex;
6666
flex-direction: column;
6767

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import pandas as pd
12
import streamlit as st
23
from mitosheet.streamlit.v1 import spreadsheet
34

45
st.set_page_config(layout="wide")
56
st.title('Tesla Stock Volume Analysis')
67

7-
CSV_URL = 'https://raw.githubusercontent.com/plotly/datasets/master/tesla-stock-price.csv'
8-
new_dfs, code = spreadsheet(CSV_URL)
8+
df = pd.DataFrame({
9+
'a': [1, 2, 3],
10+
'b': [4, 5, 6]
11+
})
12+
new_dfs, code = spreadsheet(df, height='1000px')
913

1014
st.write(new_dfs)
1115
st.code(code)

mitosheet/mitosheet/streamlit/v1/spreadsheet.py

+2
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def spreadsheet( # type: ignore
321321
import_folder: Optional[str]=None,
322322
code_options: Optional[CodeOptions]=None,
323323
return_type: str='default',
324+
height: Optional[str]=None,
324325
key=None
325326
) -> Any:
326327
"""
@@ -405,6 +406,7 @@ def spreadsheet( # type: ignore
405406
key=key,
406407
sheet_data_json=sheet_data_json, analysis_data_json=analysis_data_json, user_profile_json=user_profile_json,
407408
responses_json=responses_json, id=id(mito_backend),
409+
height=height,
408410
return_type=return_type
409411
)
410412

mitosheet/src/mito/Mito.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import { Toolbar } from './components/toolbar/Toolbar';
8080
import Tour from './components/tour/Tour';
8181
import { TourName } from './components/tour/Tours';
8282
import { useMitoAPI } from './hooks/useMitoAPI';
83-
import { getCSSVariablesFromTheme } from './utils/colors';
83+
import { getCSSStyleVariables } from './utils/colors';
8484
import { handleKeyboardShortcuts } from './utils/keyboardShortcuts';
8585
import { isInDashboard } from './utils/location';
8686
import { shallowEqualToDepth } from './utils/objects';
@@ -104,6 +104,7 @@ export type MitoProps = {
104104
textColor?: string
105105
}
106106
onSelectionChange?: (selectedDataframeIndex: number, selections: MitoSelection[]) => void;
107+
height?: string | undefined;
107108
};
108109

109110
export const Mito = (props: MitoProps): JSX.Element => {
@@ -379,20 +380,19 @@ export const Mito = (props: MitoProps): JSX.Element => {
379380
}, [uiState]);
380381

381382
/**
382-
* If the theme changes, we update the theme on the document.
383+
* If the styling changes, we update the syling on the document.
383384
* Note we don't just do this on the Mito component styles
384-
* because we want to be able to use the theme in dropdowns
385+
* because we want to be able to use the styling in dropdowns
385386
* that are rendered outside of the Mito component.
386387
*/
387388
useEffect(() => {
388-
const cssVariables = getCSSVariablesFromTheme(props.theme);
389+
const cssVariables = getCSSStyleVariables(props.height, props.theme);
389390
// For each key in the theme, set it on the document style
390391
Object.keys(cssVariables).forEach((key) => {
391392
const value = (cssVariables as Record<string, any>)[key];
392393
document.documentElement.style.setProperty(key, value);
393394
})
394-
395-
}, [props.theme])
395+
}, [props.theme, props.height])
396396

397397

398398
// If the user passes an onSelectionChange, then, we fire off events any time the user selects

mitosheet/src/mito/utils/colors.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,19 @@ const getBackgroundColors = (backgroundColor: string | undefined): React.CSSProp
9797

9898

9999

100-
export const getCSSVariablesFromTheme = (theme?: MitoTheme): React.CSSProperties => {
100+
export const getCSSStyleVariables = (height: string | undefined, theme?: MitoTheme): React.CSSProperties => {
101101

102102
const highlightTheme = getHighlightTheme(theme?.primaryColor);
103103
const textTheme = getTextColors(theme?.textColor);
104104
const backgroundTheme = getBackgroundColors(theme?.backgroundColor);
105+
const heightTheme = height ? {'--mito-height': height} : {'--mito-height': '538px'} as React.CSSProperties;
106+
105107

106108
return {
107109
...highlightTheme,
108110
...textTheme,
109111
...backgroundTheme,
112+
...heightTheme,
110113
}
111114
}
112115

mitosheet/src/streamlit/MitoStreamlitWrapper.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class MitoStreamlitWrapper extends StreamlitComponentBase<State> {
168168
public render = (): ReactNode => {
169169

170170
const returnType = this.props.args['return_type'] as string;
171+
const height = this.props.args['height'] as string | undefined;
171172
const sheetDataArray = getSheetDataArrayFromString(this.props.args['sheet_data_json']);
172173
const analysisData = getAnalysisDataFromString(this.props.args['analysis_data_json']);
173174
const userProfile = getUserProfileFromString(this.props.args['user_profile_json']);
@@ -195,6 +196,7 @@ class MitoStreamlitWrapper extends StreamlitComponentBase<State> {
195196
return (
196197
<Mito
197198
key={this.props.args['id'] as string}
199+
height={height}
198200
getSendFunction={async () => this.send.bind(this)}
199201
sheetDataArray={sheetDataArray}
200202
analysisData={analysisData}

0 commit comments

Comments
 (0)