plotly.py: ValueError(“Invalid value”) in basedatatypes.py

After upgrading to Plotly 5 (either 5.1.0 or 5.2.2, or 5.3.1, 5.4.0), I am seeing the error (given below) for various plots, at random. The issue goes away if Plotly is downgraded to 4.14.3.

File "plotly/basedatatypes.py", line 3952, in _index_is
raise ValueError("Invalid value")

Here are relevant reports from me and other users

I have a Dash app that plots several graphs. When the Dash app starts, some plots do not get displayed, and I see the error. This only occurs on the initial startup of the app. When the webpage is refreshed, the error does not re-appear, and all plots get displayed without errors.

If I downgrade to Plotly 4.14.3, the issue goes away entirely.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 5
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Fixed by adding: fig = go.Figure(layout=dict(template='plotly')) before instantiating the figure.

e.g. fig = go.Figure(layout=dict(template='plotly'))

fig = px.bar(temp_df, ...

Original poster is here. The code sample I submitted in 2021 produces the error just fine. I have just tested it again in Dash 2.15.0 and got the same error.

As many other reporters clearly indicated, the nature of this error seems random. Try running the code a few times, and opening a fresh browser tab perphaps for each try?

FYI - This same error is still occurring when using plotly/dash, in 2024. Luckily, the above fix by “KnopKirrie” still works.

In fact, you only have to include this line one time before any of your other plotly or dash code:

go.Figure(layout=dict(template=‘plotly’))