2

holoviz パネルは、データ視覚化ダッシュボードを構築するための非常に興味深いソリューションだと思います。残念ながら、jupyter ノートブックのパネル内でノード リンク ダイアグラムのベガ プロットを機能させるのに問題があります。

関連するインポートなど:

  • import panel
  • pn.extension()
  • from vega import Vega

私の調査結果:

  • vega インポートは、パネルの外で使用するとうまく機能します。https: //vega.github.io/editor/#/examples/vega/force-directed-layout からコピー/貼り付けされた Vega 仕様は、使用する必要があるように視覚化されますVega(spec)(スクリーンショットを参照してください 1)。
  • 使用pn.pane.Vega(spec)すると空きスペースができます。ソースコードを使用して外部で視覚化を実行し、pn.pane.Vega(spec).show()見ると、div が空であることがわかります (スクリーンショット 2 を参照)。

これを機能させるための助けは大歓迎です...

ありがとう、ヤン。

問題を表示するための最小限のスクリプトを次に示します。

#!/usr/bin/env python
import panel as pn
from bokeh.plotting import output_notebook
from vega import Vega
pn.extension('vega')
output_notebook()

spec = {
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 400,
  "height": 200,

  "data": [
    {
      "name": "table",
      "values": [
        {"category": "A", "amount": 28},
        {"category": "B", "amount": 55},
        {"category": "C", "amount": 43}
      ]
    }
  ],

  "scales": [
    {
      "name": "xscale",
      "type": "band",
      "domain": {"data": "table", "field": "category"},
      "range": "width"
    },
    {
      "name": "yscale",
      "domain": {"data": "table", "field": "amount"},
      "range": "height"
    }
  ],

  "marks": [
    {
      "type": "rect",
      "from": {"data":"table"},
      "encode": {
        "enter": {
          "x": {"scale": "xscale", "field": "category"},
          "width": {"scale": "xscale", "band": 1},
          "y": {"scale": "yscale", "field": "amount"},
          "y2": {"scale": "yscale", "value": 0}
        },
        "update": {
          "fill": {"value": "steelblue"}
        }
      }
    }
  ]
}

Vega(spec) # => shows barchart => OK

pn.Column(pn.panel("## Vega test"),
          pn.pane.Vega(spec),
          pn.panel("_end of test_"))
# => shows "Vega test", then empty space, the "end of test"

pn.Column(pn.panel("## Vega test"),
          pn.panel(spec),
          pn.panel("_end of test_"))
# => shows "Vega test", then empty space, the "end of test"
4

1 に答える 1

0

結論として、これはパネルのバグであり、@philippjfr によってすぐに修正されました: https://github.com/holoviz/panel/issues/872

これを機能させるには、パネル 0.7.1 が必要です。

このバージョンはまだ利用できないため、次の方法で最新バージョンのパネルをインストールできます。

pip install git+ https://github.com/holoviz/panel.git

ベガ プロットは、次のように最新バージョンのパネルで表示できます。

pn.Column(pn.pane.Vega(spec))

discourse.holoviz.org に関するこのディスカッションも参照してください:
https://discourse.holoviz.org/t/vega-plot-not-displaying-within-a-holoviz-panel-in-jupyter-notebook/49/5

于 2019-12-16T19:48:56.383 に答える