Home > Enterprise >  Type Error generated when updating a Dash Plotly graph
Type Error generated when updating a Dash Plotly graph

Time:07-03

I am running a code that produces a Dash Plotly scatter graph that can be updated using a radio button. An empty graph is generated and I am getting a callback error updating graph.figure each time I click on the radio button.

I am trying to figure out where the error is originating from and why it is occurring.

This is the error message

TypeError                                 Traceback (most recent call last)
TypeError: object of type 'int' has no len()

And this is the code

app.layout = html.Div([

    html.Div(id='radio_output'), 
    dcc.RadioItems( 
 id='radio_dropdown', 
 
options=[{'label': i, 'value': i} for i in [1.0, 2.0, 3.0]],
value=2.0
), 
             

html.Div([
    dcc.Graph(id="the_graph")]
)])

@app.callback(
    Output("the_graph", "figure"),
    Input("radio_dropdown", 'value')
)

def update_graph(selected_std_dev):
    if len(selected_std_dev) == 0:
        return dash.no_update
    else:
        max_deviations = [(RadioItems(value) == selected_std_dev)]
        dff=pd.DataFrame(dff=df)
        x = dff.TIME
        y = dff.CHANGE
        mean = np.mean(y)
        standard_deviation = np.std(y)
        distance_from_mean = abs(y - mean)
        not_outlier = distance_from_mean < max_deviations * standard_deviation
        no_outliers = y[not_outlier]
        trim_outliers = pd.DataFrame(data=no_outliers)
        dff = pd.merge(trim_outliers, df, left_index=True, right_index=True)
   
  

CodePudding user response:

The error is pretty self-explanatory. The function is passed an integer, however integers don't have any __len__ method associated with them. The len() calls the __len__ function of the object that is passed to it. docs

  • Related