Exemple #1
0
    def test_st_arrow_dataframe(self):
        """Test st._arrow_dataframe."""
        from streamlit.type_util import bytes_to_data_frame

        df = pd.DataFrame({"one": [1, 2], "two": [11, 22]})

        st._arrow_dataframe(df)

        proto = self.get_delta_from_queue().new_element.arrow_data_frame
        pd.testing.assert_frame_equal(bytes_to_data_frame(proto.data), df)
Exemple #2
0
# 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 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._arrow_dataframe(df)
st._arrow_dataframe(df, 250, 150)
st._arrow_dataframe(df, width=250)
st._arrow_dataframe(df, height=150)
Exemple #3
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 altair as alt
import numpy as np
import pandas as pd

import streamlit as st

df = pd.DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6]})

table_element = st._arrow_table(df)
dataframe_element = st._arrow_dataframe(df)
chart_element_1 = st._arrow_line_chart()
chart_element_2 = st._arrow_line_chart(df)

# 4 identical charts, built in different ways.
vega_element_1 = st._arrow_vega_lite_chart(
    df,
    {
        "mark": {
            "type": "line",
            "point": True
        },
        "encoding": {
            "x": {
                "field": "a",
                "type": "quantitative"
Exemple #4
0
# 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({"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._arrow_dataframe(df)
Exemple #5
0
# 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._arrow_dataframe(df.style.format({"test": "{:.2f}"}))
Exemple #6
0
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._arrow_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._arrow_dataframe({"foo": ["hello", "world", "foo " * 30]})

ROWS = 2

st.header("Using st._arrow_dataframe")

for cols in [4, 5, 6, 20]:
    df = pd.DataFrame(np.random.randn(ROWS, cols),
                      index=range(ROWS),
                      columns=range(cols))
Exemple #7
0
# 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
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._arrow_dataframe(df.style.applymap(highlight_first))
Exemple #8
0
# 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._arrow_dataframe()
st._arrow_dataframe([])
st._arrow_dataframe(np.array(0))
st._arrow_dataframe(pd.DataFrame([]))

st.header("Empty one-column dataframes")
st.write(np.array([]))
st._arrow_dataframe(np.array([]))

st.header("Empty two-column dataframes (only shows 1)")
st.write(pd.DataFrame({"lat": [], "lon": []}))
st._arrow_dataframe(pd.DataFrame({"lat": [], "lon": []}))

st.header("Empty tables")
st._arrow_table()
st._arrow_table([])