Thanks to visit codestin.com
Credit goes to github.com

Skip to content

vega_lite_chart displays wrong data due to premature caching optimization on the front end #6689

@vskarine

Description

@vskarine

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

  • create vega_lite_chart and populate it with some data
  • keep first and last values in the array the same as before BUT add several data points to the data but also change some data in the middle
  • Following code only checks first and last items in the array and determines that whole array is the same as before therefore no need to re-render middle parts which is absolutely wrong:
    // (this is a very light check, and not guaranteed to be right!)

Reproducible Code Example

Open in Streamlit Cloud

import pandas as pd
import streamlit as st

data1 = {
  "VALUE": [420, 380, 390],
  "DATE": [50, 60, 70]
}
data = pd.DataFrame(data1)

data2 = {
  "VALUE": [420, 200, 390, 600],
  "DATE": [50, 60, 70, 80]
}


if st.button(label="change"):
    data = pd.DataFrame(data2)
st.vega_lite_chart(
    data=pd.DataFrame(data),
    spec={
        "autosize": {
            "type": "fit",
            "contains": "padding",
            "resize": True,
        },
        "title": "test",
        "layer": [
            {
                "layer": [
                    {
                        "mark": "line",
                    },
                ],
                "encoding": {
                    "x": {
                        "field": "DATE",
                        "title": "",
                        "type": "quantitative",
                    },
                    "y": {
                        "field": "VALUE",
                        "title": "",
                        "type": "quantitative",
                    },
                },
            },
        ],
    },
    use_container_width=True,
    theme="streamlit",
)


st.vega_lite_chart(
    data=pd.DataFrame(data2),
    spec={
        "autosize": {
            "type": "fit",
            "contains": "padding",
            "resize": True,
        },
        "title": "test",
        "layer": [
            {
                "layer": [
                    {
                        "mark": "line",
                    },
                ],
                "encoding": {
                    "x": {
                        "field": "DATE",
                        "title": "",
                        "type": "quantitative",
                    },
                    "y": {
                        "field": "VALUE",
                        "title": "",
                        "type": "quantitative",
                    },
                },
            },
        ],
    },
    use_container_width=True,
    theme="streamlit",
)

Steps To Reproduce

run the code and click "change" button

Expected Behavior

charts become the same

Current Behavior

charts are different

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

it's been there for past 2 years or so

Additional Information

No response

Are you willing to submit a PR?

  • Yes, I am willing to submit a PR!

Metadata

Metadata

Assignees

Labels

feature:st.vega_lite_chartRelated to the `st.vega_lite_chart` elementpriority:P2Medium-high priority - fix within one monthstatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions