⚡️ Launched in 1.33: st.experimental_fragment

Hi, Jcarroll, I’ve tried:
https://st-experimental-fragment.streamlit.app/
,very excited you guys make this great feature which is just what I’m longing for.

I used “LLM-generated” code a lot, However, my app always cracked due to streamlit.errors.DuplicateWidgetID, which happend on this prview demo page [Chat response] as well if we tried 2 or more times chat inputs. Please find the snapshot below:

could you double check this?
1、Will this DuplicateWidgetID issue be solved when this feature released?
2、Is it possible to keep the LLM-generated code’s operation states (in this example, [Exclude internal apps] checkbox clicked or not, its auto-generated key, etc, better the line_chart zoom size )? so that when rerun or switch pages, these states will not be reset, which will be very good user expierence.

Thanks a lot. :smiley:

1 Like

@jcarroll Could you please reply this?

Thank you a lot. :smiley:

1 Like

One way to fix that code is to supply a key to the checkbox explicitly.

Define a key, using uuid.

key = str(uuid.uuid4())

Use that key for the checkbox.

exclude = st.checkbox("Exclude internal apps", key="{key}")

Complete revised code.

import uuid

def get_response(messages):
        key = str(uuid.uuid4())
        return f"""Sure, you can run the code below
```python
import streamlit as st
import pandas as pd

app_df = pd.DataFrame([[1, 1, 1], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 3]], columns=["day", "apps", "external_apps"])
exclude = st.checkbox("Exclude internal apps", key="{key}")
y = "apps" if not exclude else "external_apps"
st.line_chart(app_df, x="day", y=y)

“”"

2 Likes

@ferdy Yes. uuid is good point for us human coder to avoid duplication, Thank you, Ferdy.

when it comes to “LLM-generated” code, it would be better for LLMs to work around this without further fixing from us. :smiley:

2 Likes

I just published a new module to PyPi that will allow you to get all of the price history data you want without restrictions. I’m still working on documentation and a few other small things, but the module is available now if you would like to use it.

PyPi Module - https://pypi.org/project/quickfin/
Documentation - https://quickfin.techbyderek.com/

Installation

Open a terminal and enter the following:

pip install quickfin

Quickstart 1

Retrieve a data payload containing the most recent stock price data available for the stock symbol passed to the symbol parameter. Method will return live market price quotes during trading hours.

from quickfin import *

price_data = PriceData()

print(price_data.current("SNOW"))

Output:

{
  'current': {
    'Adj Close': 161.6,
    'Change Amount': 2.42,
    'Change Rate': 0.01,
    'Close': 161.6,
    'Date': '2024-03-28',
    'Day Range': 4.89,
    'High': 165.89,
    'Low': 161.0,
    'Open': 164.02,
    'Volume': 10106900
  },
  'info': {
    'industry': 'Software - Application',
    'name': 'Snowflake Inc.',
    'sector': 'Technology',
    'symbol': 'SNOW'
  }
}

Quickstart 2

Retrieve data payload containing all historical stock price data available for the stock symbol passed to the symbol parameter.

from quickfin import *

price_data = PriceData()

price_history = price_data.history("SNOW")

print(price_history["info"])
print(price_history["current"])
print(price_history["history"])

Output:

{'industry': 'Software - Application',
 'name': 'Snowflake Inc.',
 'sector': 'Technology',
 'symbol': 'SNOW'}

{'Adj Close': 161.6,
 'Change Amount': 2.42,
 'Change Rate': 0.01,
 'Close': 161.6,
 'Date': '2024-03-28',
 'Day Range': 4.89,
 'High': 165.89,
 'Low': 161.0,
 'Open': 164.02,
 'Volume': 10106900}

[{'Adj Close': 161.6,
  'Change Amount': 2.42,
  'Change Rate': 0.01,
  'Close': 161.6,
  'Date': '2024-03-28',
  'Day Range': 4.89,
  'High': 165.89,
  'Low': 161.0,
  'Open': 164.02,
  'Volume': 10106900},
 {'Adj Close': 160.04,
  'Change Amount': -0.44,
  'Change Rate': -0.0,
  'Close': 160.04,
  'Date': '2024-03-27',
  'Day Range': 2.93,
  'High': 160.63,
  'Low': 157.7,
  'Open': 159.6,
  'Volume': 4698100},
 {'Adj Close': 158.02,
  'Change Amount': 1.36,
  'Change Rate': 0.01,
  'Close': 158.02,
  'Date': '2024-03-26',
  'Day Range': 3.33,
  'High': 160.97,
  'Low': 157.64,
  'Open': 159.38,
  'Volume': 4069100},

      ----- snip -----

]

1 Like

Happy to share that @st.experimental_fragment was released yesterday in Streamlit 1.33! :tada: :rocket:

  • :video_game: View the demo app for more use cases and examples.
  • :open_book: Check out the docs article and API reference for more details. We’ll be adding more tutorials and examples in the coming days.
  • :rocket: Try it yourself: pip install streamlit>=1.33
6 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

Hi @xing_wei sorry for the slow response. This issue can still happen in the experimental released version.

I’m looking into a solution for the DuplicateWidgetID issue especially in the case of generated code. For your own code, you need to set a unique and persisted key= value for any widgets which is unique across chat messages.

BTW for keep the operation states, I recommend you keep the generated code in session state and render it in an identical form in each rerun. The state should be preserved that way. (this could be a conversation for a new topic, probably not here)