Uncaught Error: Script error for "plotly" http://requirejs.org/docs/errors.html#scripterror

I am learning plotly from someones code, but every time when i try to run a particular code for look at the target column to see how balanced the dataset is, an error message pop ups and session got disrupted.

popup error message:

Error occurred while loading the notebook: Uncaught Error: Script error for "plotly" http://requirejs.org/docs/errors.html#scripterror

Code that gave me error

fig = px.histogram(
    train_df, 
    x=target_column, 
    color=target_column,
    color_discrete_sequence=px.colors.qualitative.G10,
)
fig.update_layout(
    title_text='Target distribution', # title of plot
    xaxis_title_text='Value', # xaxis label
    yaxis_title_text='Count', # yaxis label
    bargap=0.2, # gap between bars of adjacent location coordinates
    paper_bgcolor=primary_bgcolor,
    plot_bgcolor=primary_bgcolor,
)
fig.update_xaxes(
    title='Target class',
    categoryorder='category ascending',
)
fig.show()

After visiting documentation i understand it is a browser related error but i do not understand how to prevent it. I am using chrome browser, and kaggle kernel.


Solution 1:

I had the same issue.

There seems to be an issue with the source from which Plotly is loaded. Changing the notebook mode might help.

from plotly.offline import plot, iplot, init_notebook_mode
init_notebook_mode(connected=True)

Taken from here:

https://www.kaggle.com/product-feedback/138599