Streamlit error using plotly - reproduced successfully outside streamlit

Hi all,

I used to have a successfully deployed app using the plotly timeline graph but since a few months I always have the error

TypeError: Object of type timedelta is not JSON serializable

I used the same code below in my IDE and it works so I am a bit confused on the issue, I updated to streamlit-1.27.2 and the issue remains

import plotly.express as px
import pandas as pd

df = pd.DataFrame([
    dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
    dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
    dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')
])

fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")
fig.update_yaxes(autorange="reversed") # otherwise tasks are listed from the bottom up
st.plotly_chart(fig)
#1st solution
pip install pandas==1.5.3

#2nd solution
pip install plotly==5.14.1 # or pip install -U plotly

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