Jupyter Notebook运行Plotly网络图示例遇Chunk加载失败错误求助
问题:Jupyter Lab运行Plotly网络图代码出现JavaScript加载错误
在Jupyter Notebook中已安装Dash,运行Plotly官方网络图示例代码后,出现以下JavaScript加载错误:
Javascript Error: Loading chunk 478 failed. (error: http://localhost:8888/lab/extensions/jupyterlab-plotly/static/478.f9a7116e09cbfb956212.js?v=f9a7116e09cbfb956212)
示例代码
import plotly.graph_objects as go import networkx as nx # Create Edges G = nx.random_geometric_graph(200, 0.125) edge_x = [] edge_y = [] for edge in G.edges(): x0, y0 = G.nodes[edge[0]]['pos'] x1, y1 = G.nodes[edge[1]]['pos'] edge_x.append(x0) edge_x.append(x1) edge_x.append(None) edge_y.append(y0) edge_y.append(y1) edge_y.append(None) edge_trace = go.Scatter( x=edge_x, y=edge_y, line=dict(width=0.5, color='#888'), hoverinfo='none', mode='lines') node_x = [] node_y = [] for node in G.nodes(): x, y = G.nodes[node]['pos'] node_x.append(x) node_y.append(y) node_trace = go.Scatter( x=node_x, y=node_y, mode='markers', hoverinfo='text', marker=dict( showscale=True, # colorscale options #'Greys' | 'YlGnBu' | 'Greens' | 'YlOrRd' | 'Bluered' | 'RdBu' | #'Reds' | 'Blues' | 'Picnic' | 'Rainbow' | 'Portland' | 'Jet' | #'Hot' | 'Blackbody' | 'Earth' | 'Electric' | 'Viridis' | colorscale='YlGnBu', reversescale=True, color=[], size=10, colorbar=dict( thickness=15, title='Node Connections', xanchor='left', titleside='right' ), line_width=2)) # Color Node Points node_adjacencies = [] node_text = [] for node, adjacencies in enumerate(G.adjacency()): node_adjacencies.append(len(adjacencies[1])) node_text.append('# of connections: '+str(len(adjacencies[1]))) node_trace.marker.color = node_adjacencies node_trace.text = node_text # Create Network Graph fig = go.Figure(data=[edge_trace, node_trace], layout=go.Layout( title='<br>Network graph made with Python', titlefont_size=16, showlegend=False, hovermode='closest', margin=dict(b=20,l=5,r=5,t=40), annotations=[ dict( text="Python code: <a href='https://plotly.com/ipython-notebooks/network-graphs/'> https://plotly.com/ipython-notebooks/network-graphs/</a>", showarrow=False, xref="paper", yref="paper", x=0.005, y=-0.002 ) ], xaxis=dict(showgrid=False, zeroline=False, showticklabels=False), yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)) ) fig.show()
错误原因分析
这个错误属于Jupyter Lab的plotly前端扩展资源加载异常,常见诱因包括:
- 版本不兼容:Jupyter Lab的
jupyterlab-plotly扩展版本与Python端的plotly库版本不匹配,导致前端资源文件与后端逻辑无法对应 - 扩展安装不完整:安装
jupyterlab-plotly扩展时出现中断,导致部分chunk资源文件缺失或损坏 - 浏览器缓存冲突:浏览器缓存了旧版本的扩展资源,与当前安装的扩展版本不兼容
- 本地资源加载失败:网络问题或文件权限问题,导致扩展的JavaScript chunk文件无法从本地Jupyter Lab服务正确加载
内容的提问来源于stack exchange,提问作者dokondr
相关产品推荐
相关产品推荐

