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 を参照)。
これを機能させるための助けは大歓迎です...
ありがとう、ヤン。
- スクリーンショット 1:スクリーンショット 1
- スクリーンショット 2:スクリーンショット 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"