2017-01-31 2 views
2

bokehのcomponentを使用して、scriptdivのHTMLレポートにグラフを埋め込むためのタグを取得しています。レポートはelementtreeで構築されています。要素ツリーにbokehコンポーネントを使用する

問題は、私が便利適切な要素を作るためにSubElementを使用しないことができることを意味し、文字列としてcomponent戻りscriptdiv、ということです。これらの文字列は、ファイルに直接書き込む場合にはうまく動作しますが、文字列を解析してプロパティを決定するためにはetreeを使用していません。それはclunky感じています。

誰かがこれに遭遇しましたか? 2つの辞書を返すためにコンポーネントを取得する方法があった場合には、このような何か素晴らしいことだ:reference documentationをチェックするために、常に良い考えです

script = { 
    tag='script', 
    type='text/javascript', 
    data=#script contents here 
} 

id= { 
    tag='div', 
    class='bk-root', 
    id='6c76dbfe-52ec-4388-b408-a3142466196e' 
} 
+0

あなたの主な質問は「IDを取得する方法」ですか?残りの部分は静的なコードなので、尋ねるだけです。(データは別にして) – renzop

+0

@renzopはい、私はスクリプトから必要なデータで、divから必要なIDだと思います。 –

答えて

2

componentsはすでに生などの情報を提供するためのキーワード引数フラグを持っていますデータでHTMLタグではありません:

wrap_script (boolean, optional) : 
    If True, the returned javascript is wrapped in a script tag. 
    (default: True) 

wrap_plot_info (boolean, optional) : If True, returns ``<div>`` strings. 
    Otherwise, return dicts that can be used to build your own divs. 
    (default: True) 

    If False, the returned dictionary contains the following information: 

    { 
     'modelid': 'The model ID, used with Document.get_model_by_id', 
     'elementid': 'The css identifier the BokehJS will look for to target the plot', 
     'docid': 'Used by Bokeh to find the doc embedded in the returned script', 
    } 
関連する問題