如何在破折号/情节中使用 iframe? (Python/HTML)

Posted

技术标签:

【中文标题】如何在破折号/情节中使用 iframe? (Python/HTML)【英文标题】:How to use iframe in dash/plotly? (Python/HTML) 【发布时间】:2021-02-20 12:08:03 【问题描述】:

我正在创建一个仪表板,我想使用这个交互式地图

网页链接:https://www.ons.gov.uk/peoplepopulationandcommunity/healthandsocialcare/causesofdeath/articles/deathsinvolvingcovid19interactivemap/2020-06-12

嵌入代码: <iframe height="1043px" width="100%" src="https://www.ons.gov.uk/visualisations/dvc914/map/index.html"></iframe>

现在我对 HTML 了解不多,但这是我目前所掌握的。我知道布局是错误的,但我已经被困了很长一段时间,谁能指出我正确的方向。非常感谢!

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
from dash.dependencies import Input, Output

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)


#H1 = biggest heading,  Div = a box containhg info
app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure=fig
        
    <iframe   src="https://www.ons.gov.uk/visualisations/dvc914/map/index.html"></iframe>
    )
])

if __name__ == '__main__':
    app.run_server(debug=True,port=8049,host='127.0.0.1')

【问题讨论】:

【参考方案1】:

你快到了。只需将 iframe 元素的 语法替换为您用于其他元素的破折号语法,

import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        # figure=fig  # commented out to make the example runnable
    ),

    html.Iframe(src="https://www.ons.gov.uk/visualisations/dvc914/map/index.html",
                style="height": "1067px", "width": "100%")
])

if __name__ == '__main__':
    app.run_server(debug=True, port=8049, host='127.0.0.1')

【讨论】:

如何获取高度来包裹整个 HTML 而不是指定确切的像素?

以上是关于如何在破折号/情节中使用 iframe? (Python/HTML)的主要内容,如果未能解决你的问题,请参考以下文章

1 页上的多个情节情节,没有子情节

另一个破折号/情节困境

wps如何输入连续的长破折号

用于情节热图的交互式 zmax?

python: dash 实况情节图例

Plotly-Dash:反应迟钝的情节