Plotly-dash python - exactly same code but different result? One working and one are not?

Viewed 77

I run this plotly dash using jupyter notebook & Firefox. problem is, if I typed it manually it's not working? But when I try copied from script provided by my course it's exactly work as it is. The code is same, formating is also same. But why? I learn python from beginning since last week, problem like this is challenging lol.

what I am trying to do with this code is to create Graph interaction between scatter and line using hover.

here is the code, I copy it directly from different .ipyb file. One is mine typed manually, and others is from script.

this is my code, typed manually.

def callback_graph(hoverData):
    v_index = hoverData['points'][0]['pointIndex']
    fig = {
        'data':[go.Scatter(
            x = [0,1],
            y = [0,60/df.iloc[v_index]['acceleration']],
            mode='lines',
            line={'width':2*df.iloc[v_index]['cylinders']}
         )],
         'layout':go.Layout(
                 title = df.iloc[v_index]['name'],
                 xaxis  = {'visible':False},
                 yaxis  = {'visible':False,'range':[0,60/df['acceleration'].min()]},
                 margin = {'1':0},
                 height = 300
         )
    }
    return fig

and this is code from script provided by my online course:

def callback_graph(hoverData):
    v_index = hoverData['points'][0]['pointIndex']
    fig = {
        'data': [go.Scatter(
            x = [0,1],
            y = [0,60/df.iloc[v_index]['acceleration']],
            mode='lines',
            line={'width':2*df.iloc[v_index]['cylinders']}
        )],
        'layout': go.Layout(
            title = df.iloc[v_index]['name'],
            xaxis = {'visible':False},
            yaxis = {'visible':False, 'range':[0,60/df['acceleration'].min()]},
            margin = {'l':0},
            height = 300
        )
    }
    return fig
0 Answers
Related