[solved] The plotly chart's "newshape_label" doesn't show up while using st.plotly_chart function

Summary

Hi, I am trying to create an app with stremlit and found the st.plotly_chart doesn’t show the same result as I ran in jupyter notebook. The line I drew doesn’t show the slope when using st.plotly_chart.

Below is the result from jupyter


and below is the snapshot from streamlit

Info:

I ran it locally with python - 3.11.3, streamlit -1.27.2 and plotly - 5.17.0

###Expected behavior:
Create plot that contains data deom the dataframe and user can draw a line and it’ll show the line’s slope base on the plot’s axes on the plot. The st.plot_chart will show the same object as what I get from the jupyter notebook.

###Actual behavior:
Surprisingly, the slope doesn’t presented in the chart with st.plot_chart. :thinking:

The script I used:

import streamlit as st
import plotly.express as px
import plotly.graph_objects as go

df = px.data.iris()
groups=df['species'].unique()
data1 = []
for group in range(len(groups)):
    df_group = df[df['species']==groups[group]]
    trace = go.Scatter(x=df_group["sepal_width"], y=df_group["sepal_length"], mode='markers',name=groups[group])
    data1.append(trace)

fig = go.Figure(data=data1,layout = go.Layout(height=800,xaxis_title="sepal_width",yaxis_title="sepal_length",newshape_label=dict(texttemplate="Slope: %{slope:.2f}")))
#fig.show(config=dict(modeBarButtonsToRemove=["select2d","lasso2d"], modeBarButtonsToAdd=["drawline","eraseshpae"])) #use this line when you run the code in jupyter

st.plotly_chart(fig, use_container_width=True,theme=None,config=dict(modeBarButtonsToRemove=["select2d","lasso2d"], modeBarButtonsToAdd=["drawline","eraseshpae"]))

###Problem solved:
either using stremalit-nightly(need to unintsall the streamlit 1st, install it and call it by import streamlit) or wait for streamlit’s 1.28.0 release will work

Hey @angrygrizzard, welcome to our forum! :balloon:

Thanks for raising the issue. I was able to replicate that also on my end. Would you mind creating a GitHub issue in here so our engineering team can have a look? https://guthub.com/streamlit/streamlit/issues

Best,

Sure! :grin:

put the link here for traceability.

BR,

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