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.
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.
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
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
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.