欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

解决pyecharts运行后产生的html文件用浏览器打开空白

时间:2021-02-03 18:27:39|栏目:Python代码|点击:

根据网站资源引用说明:pyecharts 使用的所有静态资源文件存放于 pyecharts-assets 项目中,默认挂载在 https://assets.pyecharts.org/assets/

因为默认优先从远程引用资源,这就导致有的时候无法加载js文件,图表显示不出来

解决办法:

下载所需js文件到本地,修改资源引用地址

看网站的介绍,pyecharts 提供了更改全局 HOST 的快捷方式

官方下载

pyecharts-assets 提供了 pyecharts 的静态资源文件。

可通过 localhost-server 或者 notebook-server 启动本地服务。首先将项目下载到本地

# 通过 git clone
$ git clone https://github.com/pyecharts/pyecharts-assets.git

# 或者直接下载压缩包
$ wget https://github.com/pyecharts/pyecharts-assets/archive/master.zip

Localhost-Server

启动服务器

$ cd pyecharts-assets
$ python -m http.server

设置 host

# 只需要在顶部声明 CurrentConfig.ONLINE_HOST 即可
from pyecharts.globals import CurrentConfig

CurrentConfig.ONLINE_HOST = "http://127.0.0.1:8000/assets/"

# 接下来所有图形的静态资源文件都会来自刚启动的服务器
from pyecharts.charts import Bar
bar = Bar()

Notebook-Server

安装扩展插件

$ cd pyecharts-assets
# 安装并激活插件
$ jupyter nbextension install assets
$ jupyter nbextension enable assets/main

设置 host

# 只需要在顶部声明 CurrentConfig.ONLINE_HOST 即可
from pyecharts.globals import CurrentConfig, OnlineHostType

# OnlineHostType.NOTEBOOK_HOST 默认值为 http://localhost:8888/nbextensions/assets/
CurrentConfig.ONLINE_HOST = OnlineHostType.NOTEBOOK_HOST

# 接下来所有图形的静态资源文件都会来自刚启动的服务器
from pyecharts.charts import Bar
bar = Bar()

tips:

CurrentConfig.ONLINE_HOST = http://127.0.0.1:8000/assets/

可以直接修改为本机目录:

CurrentConfig.ONLINE_HOST = "E:/Software/pyecharts-assets-master/assets/"

上一篇:为什么称python为胶水语言

栏    目:Python代码

下一篇:使用python从三个角度解决josephus问题的方法

本文标题:解决pyecharts运行后产生的html文件用浏览器打开空白

本文地址:http://www.codeinn.net/misctech/56384.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有