def test_st_legacy_dataframe(self): """Test st._legacy_dataframe.""" df = pd.DataFrame({"one": [1, 2], "two": [11, 22]}) st._legacy_dataframe(df) el = self.get_delta_from_queue().new_element self.assertEqual(el.data_frame.data.cols[0].int64s.data, [1, 2]) self.assertEqual(el.data_frame.columns.plain_index.data.strings.data, ["one", "two"])
def _get_unnamed_data_methods(self): """DeltaGenerator methods that do not produce named datasets.""" return [ lambda df: st._legacy_dataframe(df), lambda df: st._legacy_table(df), lambda df: st._legacy_vega_lite_chart( df, {"mark": "line", "encoding": {"x": "a", "y": "b"}} ), # TODO: _legacy_line_chart, _legacy_bar_chart, etc. ]
# Copyright 2018-2021 Streamlit Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import streamlit as st import pandas as pd df = pd.DataFrame({"test": [3.14, 3.1]}) st._legacy_dataframe(df.style.format({"test": "{:.2f}"}))
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import streamlit as st import pandas as pd import numpy as np st.header("Empty list") st.write([]) st.header("Empty dataframes") st.write(np.array(0)) st.write(pd.DataFrame([])) st._legacy_dataframe() st._legacy_dataframe([]) st._legacy_dataframe(np.array(0)) st._legacy_dataframe(pd.DataFrame([])) st.header("Empty one-column dataframes") st.write(np.array([])) st._legacy_dataframe(np.array([])) st.header("Empty two-column dataframes (only shows 1)") st.write(pd.DataFrame({"lat": [], "lon": []})) st._legacy_dataframe(pd.DataFrame({"lat": [], "lon": []})) st.header("Empty tables") st._legacy_table() st._legacy_table([])
# Copyright 2018-2021 Streamlit Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import streamlit as st import pandas as pd import numpy as np def highlight_first(value): color = "yellow" if value == 0 else "white" return "background-color: %s" % color grid = np.arange(0, 100, 1).reshape(10, 10) df = pd.DataFrame(grid) st._legacy_dataframe(df.style.applymap(highlight_first))
# Copyright 2018-2022 Streamlit Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import streamlit as st import pandas as pd df = pd.DataFrame({"str": ["2020-04-14 00:00:00"]}) df["notz"] = pd.to_datetime(df["str"]) df["yaytz"] = pd.to_datetime(df["str"]).dt.tz_localize("Europe/Moscow") st._legacy_dataframe(df)
# Copyright 2018-2021 Streamlit Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import streamlit as st import numpy as np import pandas as pd # Explicitly seed the RNG for deterministic results np.random.seed(0) data = np.random.randn(100, 100) df = pd.DataFrame(data) st._legacy_dataframe(df) st._legacy_dataframe(df, 250, 150) st._legacy_dataframe(df, width=250) st._legacy_dataframe(df, height=150)
# * 4 vega-lite charts # * And then all of the above once again. # (Also, all of the above should have 3 rows or datapoints.) # * Then all of the above but with no data. # * Then a 1-row dataframe and an error num_rows = 3 df = pd.DataFrame({"a": [1, 2, 3], "b": [10, 0, 30], "c": [100, 200, -100]}) df1 = df.iloc[0:1, :] for test_type in ["coalesce in Py", "coalesce in JS", "clear after addrows"]: table_el = st._legacy_table(df1) dataframe_el = st._legacy_dataframe(df1) chart_el1 = st._legacy_line_chart() chart_el2 = st._legacy_line_chart(df1) # 4 identical charts, built in different ways. vega_el1 = st._legacy_vega_lite_chart( df1, { "mark": { "type": "line", "point": True }, "encoding": { "x": { "field": "a", "type": "quantitative"
np.random.seed(0) st.title("Tables with different sizes") st.header("Long cells that overflow") st.write(""" Long text should show an ellipsis. All cells should have a tooltip with their entire un-ellipsized contents. """) st._legacy_dataframe({ "foo": ["hello", "world", "foo " * 30], "bar": ["hello", "world", "bar" * 30], "baz": [1, 2, 3], "boz": [1, 2, 3], "buz": [1, 2, 3], "biz" * 30: [1, 2, 3], "bim": [1, 2, 3], }) st._legacy_dataframe({"foo": ["hello", "world", "foo " * 30]}) ROWS = 2 st.header("Using st._legacy_dataframe") for cols in [4, 5, 6, 20]: df = pd.DataFrame(np.random.randn(ROWS, cols), index=range(ROWS), columns=range(cols))