Plotly Ghost line in streamlit app

I am creating an app using streamlit which runs 24/7 on a VPS. It fetches real-time data from database. The data is plotted through plotly library. I have to use colored lines this I plot the base line then add colored line on top of the baseline.

Upon plotting sometime ghost line appears on the app. Those lines are not hover able. This issue is running when the app is running for long time. The ghost line appears below the actual colored line.

Upon restarting the app the problem goes away. Please correct me if I am doing something wrong.
Using psycopg2 for connection to database.
charting code here->

cur.execute(f"SELECT DISTINCT(timeframe) FROM symbolsdata WHERE symbol='{selectedScreener}'")
tf=[i[0] for i in cur.fetchall()]
sorterFunc=lambda x: ["1s","1m","3m","5m","15m","30m","1h","2h","4h","6h","12h","1d","3d","1w","1M"].index(x)
tf.sort(key=sorterFunc)

tfs=np.array_split(tf,4)
for name,data in config["screenerTimeframeCompareType1"].items():
st.header(name)
cols=st.columns([1 for i in range(len(tfs))])
for index,tf in enumerate(tfs):
    for t in tf:
        container=cols[index].container()
        container.subheader(t)

        fig=go.Figure()

        cur.execute(f"SELECT timestamp,{data['value']} FROM symbolsdata WHERE symbol='{selectedScreener}' AND timeframe='{t}' ORDER BY timestamp DESC LIMIT {data['range']}")
        df=[i for i in cur.fetchall()]
        df=pd.DataFrame(df)
        df.set_index(df.columns[0],inplace=True)
        df.columns=[name]
        df["color"]=list(df.applymap(data["color"])[name])
        isFirstStorke=True
        trace=[]
        for i,c in enumerate(data["colorSequence"][::1]):
            df1=df.copy()
            if isFirstStorke:
                # df1.loc[df1["color"]!=c,name]=None
                isFirstStorke=False
            else:
                df1.loc[df1["color"]!=c,name]=None
            
            trace.append(
                go.Scatter(
                    x=df1.index,
                    y=df1[name],
                    mode=data["type"],
                    line_color=c
                    # line_width=i+1  
                    # marker_color=df["color"]
                )
            )
        fig.add_traces(trace[::-1])

        fig.update_layout(height=200,margin={"r":20,"l":20,"t":50,"b":10},showlegend=False,)
        fig.update_yaxes(range=data["chartRange"] if data["chartRange"] else None)
        container.plotly_chart(fig,use_container_width=True)

        container.markdown(f"<span style='text-align:right;width:100%;display:inline-block;'>Mn:{round(df[df.columns[0]].min())}|Mx:{round(df[df.columns[0]].max())}|C:{round(df.iloc[-1][name],2)}</span>",unsafe_allow_html=True)

The issue is not common when I restart the app.
It seems that this is some kind of caching issue. But I haven’t done anything to cache in the whole app.

1 Like

Hi @XotEmBotZ ,

We also noticed this and opened an issue on GitHub (see below). Like the comments in there so the Streamlit team knows there are many of us affected :slight_smile: Thanks!

Thanks for the information.
I appreciate the team’s work in the project.
Just for information is there any work around for this bug. As I have to submit the project. Like disable the caching as whole. If any is there, then kindly inform me. I am ready to disable caching as a whole.

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