示例#1
0
    def test_arrow_line_chart(self):
        """Test st._arrow_line_chart."""
        df = pd.DataFrame([[20, 30, 50]], columns=["a", "b", "c"])
        EXPECTED_DATAFRAME = pd.DataFrame(
            [[0, "a", 20], [0, "b", 30], [0, "c", 50]],
            index=[0, 1, 2],
            columns=["index", "variable", "value"],
        )

        st._arrow_line_chart(df)

        proto = self.get_delta_from_queue().new_element.arrow_vega_lite_chart
        chart_spec = json.loads(proto.spec)
        self.assertEqual(chart_spec["mark"], "line")
        pd.testing.assert_frame_equal(
            bytes_to_data_frame(proto.datasets[0].data.data),
            EXPECTED_DATAFRAME,
        )
示例#2
0
    def test_st_arrow_line_chart(self):
        """Test st._arrow_line_chart."""
        from streamlit.type_util import bytes_to_data_frame

        df = pd.DataFrame([[10, 20, 30]], columns=["a", "b", "c"])
        EXPECTED_DATAFRAME = pd.DataFrame(
            [[0, "a", 10], [0, "b", 20], [0, "c", 30]],
            index=[0, 1, 2],
            columns=["index", "variable", "value"],
        )
        st._arrow_line_chart(df, width=640, height=480)

        proto = self.get_delta_from_queue().new_element.arrow_vega_lite_chart
        chart_spec = json.loads(proto.spec)

        self.assertEqual(chart_spec["mark"], "line")
        self.assertEqual(chart_spec["width"], 640)
        self.assertEqual(chart_spec["height"], 480)
        pd.testing.assert_frame_equal(
            bytes_to_data_frame(proto.datasets[0].data.data),
            EXPECTED_DATAFRAME,
        )
# 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.
"""
This example was failing due to an issue (#3653) in st._arrow_add_rows.
In the previos implementation of Quiver, we were mutating the Quiver element
in the addRows function, which prevented re-rendering of the line chart.
This example reproduces the issue, so that we don't repeat the same mistake
in the future.
"""

import time

import pandas as pd
import streamlit as st

current_time = pd.to_datetime("08:00:00 2021-01-01", utc=True)
simulation_step = pd.Timedelta(seconds=10)

df1 = pd.DataFrame(data=[[current_time, 1]], columns=["t", "y"]).set_index("t")
line_chart = st._arrow_line_chart(df1, use_container_width=True)

for count in range(5):
    current_time += simulation_step

    df2 = pd.DataFrame(data=[[current_time, count]],
                       columns=["t", "y"]).set_index("t")
    # This issue is Arrow specific, that's why st._legacy_add_rows doesn't have a similar test.
    line_chart._arrow_add_rows(df2)
    time.sleep(1)
示例#4
0
 def _get_deltas_that_melt_dataframes(self):
     return [
         lambda df: st._arrow_line_chart(df),
         lambda df: st._arrow_bar_chart(df),
         lambda df: st._arrow_area_chart(df),
     ]
示例#5
0
data = pd.DataFrame({"a": [1, 2, 3, 4], "b": [1, 3, 2, 4]})

spec = {
    "mark": "line",
    "encoding": {
        "x": {"field": "a", "type": "quantitative"},
        "y": {"field": "b", "type": "quantitative"},
    },
}

# 5 empty charts
st._arrow_vega_lite_chart(spec, use_container_width=True)
fig, ax = plt.subplots()
st.pyplot(fig, use_container_width=True)
st._arrow_line_chart()
st._arrow_bar_chart()
st._arrow_area_chart()

# 1 empty map
# comment this one out to avoid this Cypress-Mapbox related error.
# ref: https://github.com/cypress-io/cypress/issues/4322
# st.pydeck_chart()
# st.map()

# 6 errors
try:
    st._arrow_vega_lite_chart({}, use_container_width=True)
except Exception as e:
    st.write(e)
示例#6
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 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"
            },
示例#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 numpy as np
import pandas as pd

data = np.random.randn(20, 3)
df = pd.DataFrame(data, columns=["a", "b", "c"])
st._arrow_line_chart(df)