時間:2023-07-21 03:48:01 | 來源:網(wǎng)站運(yùn)營
時間:2023-07-21 03:48:01 來源:網(wǎng)站運(yùn)營
pyecharts 采用本地靜態(tài)資源生成html,離線可訪問。:# 通過 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
設(shè)置 host# 只需要在頂部聲明 CurrentConfig.ONLINE_HOST 即可from pyecharts.globals import CurrentConfigCurrentConfig.ONLINE_HOST = "http://127.0.0.1:8000/assets/"# 接下來所有圖形的靜態(tài)資源文件都會來自剛啟動的服務(wù)器from pyecharts.charts import Barbar = Bar()
再次運(yùn)行生成html源代碼如下,離線斷網(wǎng)情況也可以正常打開:# 只需要在頂部聲明 CurrentConfig.ONLINE_HOST 即可from pathlib import Pathfrom pyecharts.globals import CurrentConfig# 本地靜態(tài)資源assets 目錄路徑static_resource = Path(__file__).parents[1] / 'pyecharts' / 'pyecharts-assets' / 'assets'# windows環(huán)境下 / 替換為 /, *nix環(huán)境請按需修改CurrentConfig.ONLINE_HOST = str(static_resource).replace("//", r'/') + '/'# 接下來所有圖形的靜態(tài)資源文件都會來自本地指定的靜態(tài)資源from pyecharts.charts import Barbar = Bar()
生成的html源代碼如下,不啟用http.server情況下斷網(wǎng)時可正常打開:$ cd pyecharts-assets# 安裝并激活插件$ jupyter nbextension install assets$ jupyter nbextension enable assets/main
設(shè)置 host # 只需要在頂部聲明 CurrentConfig.ONLINE_HOST 即可from pyecharts.globals import CurrentConfig, OnlineHostType# OnlineHostType.NOTEBOOK_HOST 默認(rèn)值為 http://localhost:8888/nbextensions/assets/CurrentConfig.ONLINE_HOST = OnlineHostType.NOTEBOOK_HOST# 接下來所有圖形的靜態(tài)資源文件都會來自剛啟動的服務(wù)器from pyecharts.charts import Barbar = Bar()
關(guān)鍵詞:訪問,采用,本地,靜態(tài),資源
客戶&案例
營銷資訊
關(guān)于我們
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。