Can you please explain this error message (TypeError: bar() got an unexpected keyword argument 'text_auto') and how to fix it?

Strangely, I am not finding much information anywhere about this error message. The one response I found proposed upgrading to Plotly 5.5. I re-installed the latest version, which is 5.4…apparently:


"(venv) C:\Users\rober\ings>pip install plotly
Requirement already satisfied: plotly in c:\users\rober\ings\venv\lib\site-packages (5.4.0)
Requirement already satisfied: six in c:\users\rober\ings\venv\lib\site-packages (from plotly) (1.16.0)
Requirement already satisfied: tenacity>=6.2.0 in c:\users\rober\ings\venv\lib\site-packages (from plotly) (8.0.1)"

May I ask, what is going on and how can I fix it?

Here is the full Traceback message:


Traceback (most recent call last):
  File "C:\Users\rober\ings\checklist.py", line 72, in update_graph
    barchart = px.bar(df, y='Amounts', x='Nutrients', text_auto=True,
TypeError: bar() got an unexpected keyword argument 'text_auto'

Below, I pasted the code I am currently using to produce the figure, which is (more or less) straight from the documentation. If I remove the text_auto argument, it produces the graph without the labels.

Changing the argument to “True” produces the same error message.

Thank you for reviewing my question.


@app.callback(
    Output(component_id='the_graph', component_property='figure'),
    [Input(component_id='nutrient_checklist', component_property='value')]
)
def update_graph(options_chosen):

    dff = df[df['Nutrients'].isin(options_chosen)]
    print (dff['Nutrients'].unique())

    barchart = px.bar(df, y='Amounts', x='Nutrients', text_auto='.2s', title="Controlled text sizes, positions and angles")
    barchart.update_traces(textfont_size=12, textangle=0, textposition="outside", cliponaxis=False)
    barchart.show()

    return (barchart)

Robert

This worked for me.

pip install plotly==5.5.0

More info can be found here: plotly · PyPI

Hi there,

Yes. That is part of what ultimately worked for me,though my experience was a little more complicated, and I will share it here again for posterity’s sake. As I wrote in a response to Adam…

My apologies. I worked on this all day yesterday, and I was in a rush to yoga class last night when I asked the question.

Ultimately, I think I solved the mystery.

I will explain what I found in detail in case it helps someone in the future.

  1. I found you must run Plotly 5.5 for text_auto to work on any chart. For some reason, I was running 5.4 which caught me by surprise because I installed it only weeks ago.

  2. To resolve the issue, I had to use this command: pip install plotly==5.5. if I ran pip install plotly, without specifying the version, it will still install 5.4 as of this morning.

  3. Once I had installed 5.5, the text_auto argument works, but it only works in Plotly Express charts, where “px.bar” is used to draw the figure. See Bar Charts with Text in the documentation for an example.

  4. I needed a chart like Bar Chart with Relative Barmode (in the same documentation), because I need to compare the final results to nutritional benchmarks. Instead of “px.bar,” it requires “fig = go.Figure()” to draw the chart. It does not accept the “text_auto” argument with producing this error message:

ValueError: 'NoneType' object is not subscriptable

Invalid value received for the 'text' property of bar

    The 'text' property is a string and must be specified as:
      - A string
      - A number that will be converted to a string
      - A tuple, list, or one-dimensional numpy array of the above

Property does not support subscripting:
text_auto

Fortunately, the graph entitled “Rotated Bar Chart Labels” in the documentation should not only enable me to use labels, but it also includes the “barmode=‘group’” argument that should allow me to compare actual levels to benchmarks. It met my needs should meet my needs.

Robert