'Uncaught Error: Script error for "plotly" http://requirejs.org/docs/errors.html#scripterror
I am learning plotly
from someone's 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:[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:
Solution 2:[2]
This is a common type of error we get when working on Kaggle. We need to maintain the offline version of plotly for interactive charts.
The code will be:
from plotly.offline import iplot, init_notebook_mode
import plotly.express as px
init_notebook_mode(connected=True)
fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
iplot(fig)
You can also refer to my Kaggle notebook on plotly based visualizations from here: https://www.kaggle.com/vardhansiramdasu/student-performance-analysis
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | vardhan SIRAMDASU |