2017-01-31 23 views
2

我使用的是散景的component以獲取scriptdiv用於將圖形嵌入html報告中的標記。該報告使用elementtree構建。在elementtree中使用散景成分

問題是component返回scriptdiv作爲字符串,這意味着我不能方便地使用SubElement來製作適當的元素。如果直接寫入文件,這些字符串可以正常工作,但是我使用etree來解析字符串並確定屬性。感覺很笨重。

有沒有其他人遇到過這個問題?這將是巨大的,如果有一種方式來獲得部分回兩個字典,像這樣:

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

它總是一個好主意,檢查reference documentationcomponents已有關鍵字參數標誌提供的信息爲原料數據而不是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', 
    }