簡體   English   中英

如何在 python-dash-bootstrap-components 中渲染 html?

[英]how to render html in python-dash-bootstrap-components?

我已經嘗試了很多東西,但我無法讓這段代碼呈現。 不幸的是,它在瀏覽器中僅顯示為字符串。

變量“html 代碼”包含顯示 Tradingview 圖表的代碼,但它僅顯示為字符串。

有人知道嗎?

import dash
from dash import html
import dash_bootstrap_components as dbc

app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

html_code = '''
<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
  <div id="tradingview_8906e"></div>
  <div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/NASDAQ-AAPL/" rel="noopener" target="_blank"><span class="blue-text">AAPL stock chart</span></a> by TradingView</div>
  <script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
  <script type="text/javascript">
  new TradingView.widget(
  {
  "autosize": true,
  "symbol": "NASDAQ:AAPL",
  "interval": "D",
  "timezone": "Etc/UTC",
  "theme": "light",
  "style": "1",
  "locale": "en",
  "toolbar_bg": "#f1f3f6",
  "enable_publishing": false,
  "allow_symbol_change": true,
  "container_id": "tradingview_8906e"
}
  );
  </script>
</div>
<!-- TradingView Widget END -->
'''

container = html.Div(html_code)

column = dbc.Col(
    [
        container
    ]
)

app.layout = html.Div([
    dbc.Container(
        [
            dbc.Row(
                [
                    column,
                ]
            ),
        ]
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

要使用 Bootstrap 組件在 Python Dash 中呈現 HTML,您可以使用 dash-bootstrap-components 庫提供的 dbc.Jumbotron 組件。

我一直在研究,我想我已經找到了答案。 解決方案是“html.Iframe”Object。看起來它正在工作,只需要弄亂大小即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM