带破折号输出的HTML iframe

anauzrmj  于 2023-06-04  发布在  其他
关注(0)|答案(1)|浏览(220)

我有两个非常简单的 Jmeter 板,我想用flask运行这两个 Jmeter 板,使用main.py路由。
app1.py

import dash
from dash import html, dcc

app = dash.Dash(__name__)

app.layout = html.Div(
    children=[
        html.H1('App 1'),
        dcc.Graph(
            id='graph1',
            figure={
                'data': [{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'App 1'}],
                'layout': {
                    'title': 'App 1 Graph'
                }
            }
        )
    ]
)

和/或
app2.py

import dash
from dash import html, dcc

app = dash.Dash(__name__)

app.layout = html.Div(
    children=[
        html.H1('App 2'),
        dcc.Graph(
            id='graph2',
            figure={
                'data': [{'x': [1, 2, 3], 'y': [2, 4, 1], 'type': 'bar', 'name': 'App 2'}],
                'layout': {
                    'title': 'App 2 Graph'
                }
            }
        )
    ]
)

main.py

# main_app.py
from flask import Flask, render_template
import app1
import app2

app = Flask(__name__)

@app.route('/')
def index():
    return 'Main App'

@app.route('/app1')
def render_dashboard1():
    return render_template('dashboard1.html')

@app.route('/app2')
def render_dashboard2():
    return render_template('dashboard2.html')

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

dashboard1.html

<!-- dashboard1.html -->
<!DOCTYPE html>
<html>
<head>
    <title>Dashboard 1</title>
</head>
<body>
    <h1>Dashboard 1</h1>
    <iframe src="/app1" width="1000" height="800"></iframe>
</body>
</html>

dashboard2.html

<!-- dashboard2.html -->
<!DOCTYPE html>
<html>
<head>
    <title>Dashboard 2</title>
</head>
<body>
    <h1>Dashboard 2</h1>
    <iframe src="/app2" width="1000" height="800"></iframe>
</body>
</html>

结构

/
app1.py
app2.py
main.py
/templates
dashboard1.html
dashboard2.html

但是当我运行我的main.py和app 1的路由时,我可以看到app 1的帧,但是没有图形。有人能解释一下如何使用iframe来让我能够看到输出吗?

7eumitmz

7eumitmz1#

我不能用你的代码访问模板,我认为dask使用flask,所以这可能会导致问题。我所做的是调用两个dash应用程序和一个flask应用程序;* * main.py**:

from flask import Flask, render_template
from app1 import create_app as create_app1
from app2 import create_app as create_app2

server = Flask(__name__)
app1 = create_app1(server)
app2 = create_app2(server)

@server.route('/')
def index():
    return 'Main App'

def render_dashboard1():
    return render_template('dashboard1.html')

def render_dashboard2():
    return render_template('dashboard2.html')

if __name__ == '__main__':
    server.run(debug=True)

对每个app使用create_app方法,app1.py

import dash
from dash import html, dcc

def create_app(server):
    app = dash.Dash(server=server, routes_pathname_prefix='/app1/')

    app.layout = html.Div(
        children=[
            html.H1('App 1'),
            dcc.Graph(
                id='graph1',
                figure={
                    'data': [{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'App 1'}],
                    'layout': {
                        'title': 'App 1 Graph'
                    }
                }
            )
        ]
    )

    return app

app2.py(我更改了y的值,以确保它正在阅读app 2模板):

import dash
from dash import html, dcc

def create_app(server):
    app = dash.Dash(server=server, routes_pathname_prefix='/app2/')

    app.layout = html.Div(
        children=[
            html.H1('App 2'),
            dcc.Graph(
                id='graph2',
                figure={
                    'data': [{'x': [1, 2, 3], 'y': [10, 10, 10], 'type': 'bar', 'name': 'App 2'}],
                    'layout': {
                        'title': 'App 2 Graph'
                    }
                }
            )
        ]
    )

    return app

我可以正确地看到两个图表。

相关问题