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

Skip to content

Conversation

@kmcgrady
Copy link
Collaborator

@kmcgrady kmcgrady commented Jan 7, 2025

Describe your changes

We have a shortcut included to guess if the data is an extension of the original data. This has caused issues in ensuring the data works as expected. We want to make sure we only do this if the data is newly added.

GitHub Issue Link (if applicable)

Closes #6689

Testing Plan

  • Manual testing for the following:
    • add rows triggers an insert and not a new data
    • The same data does not update the data.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@kmcgrady kmcgrady added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Jan 7, 2025
@lukasmasuch
Copy link
Collaborator

lukasmasuch commented Jan 8, 2025

I think the PR only fixes the case if the incoming data changes via add_rows but not the case when the chart at the same delta path changes its data. And I think the second case is probably much more common since add_rows usage is almost non-existent (0.036% of all apps for table+dataframe+all vega-based charts).

If I run this example, it is not updating the chart for me when clicking on "change":

import pandas as pd

import streamlit as st

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

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


if st.button(label="change"):
    data = pd.DataFrame(data2)

st.dataframe(data)
st.vega_lite_chart(
    data=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",
)

I think we can entirely remove the dataIsAnAppendOfPrev optimization and just have a check if it looks like the same data and otherwise replace the full data:

 if (prevData.hash !== data.hash) {
        view.data(name, getDataArray(data))
  }

One option could be a hash calculated in the backend for the full bytes (as you have proposed before) or a more lightweight "hash" prototyped here (that's not perfect but probably more reliable than the current version): #10139

I think we could start with the lightweight hash and eventually replace it with a backend-calculated hash since it might also be needed for lazy-loading.

@kmcgrady kmcgrady force-pushed the fix/dont-shortcut-data-check branch from 1b0afdb to e2a2f1b Compare January 8, 2025 23:32
@kmcgrady kmcgrady changed the title Ensure inserts in data for Vega Lite are confirmed from st.add_rows Remove shortcut to data checking and substitute with a rough hash Jan 8, 2025
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍



def test_vega_lite_chart_updates_with_slightly_different_data(
themed_app: Page, assert_snapshot: ImageCompareFunction
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can probably use app instead of themed_app to lower the number of snapshots (since the behavior doesn't really depend on theming).

@kmcgrady kmcgrady merged commit 63311a4 into develop Jan 9, 2025
33 checks passed
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
…reamlit#10125)

## Describe your changes

We have a shortcut included to guess if the data is an extension of the
original data. This has caused issues in ensuring the data works as
expected. We want to make sure we only do this if the data is newly
added.

## GitHub Issue Link (if applicable)
Closes streamlit#6689

## Testing Plan

- Manual testing for the following:
   - add rows triggers an insert and not a new data
   - The same data does not update the data.
---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
@kmcgrady kmcgrady deleted the fix/dont-shortcut-data-check branch March 10, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants