Black Lives Matter. Please consider donating to Black Girls Code today.

How to load html file directly on Dash

Hi,

I am trying to load html file “test2.html” directly on Dash. Please how can I go about this, I have the following code snippet:

from flask import Flask
import flask
import webbrowser
import os

STATIC_PATH = os.path.join(os.path.dirname(os.path.abspath(file)), ‘static’)

server = Flask(name)
app = dash.Dash(name = name, server = server)

app.layout = html.Div(
html.Iframe(src=’/home/makinde/test2.html’)
)

@server.route(’/static/path:path’)
def serve_static(path):
root_dir = os.getcwd()
return flask.send_from_directory(os.path.join(root_dir, ‘static’), path)

if name == ‘main’:
app.run_server(host=‘0.0.0.0’, port=8090)

There is probably a better way to do what you are trying to do, but you can load raw HTML in using the https://github.com/plotly/dash-dangerously-set-inner-html package i made an example here with both statically loaded HTML and generated html from pandas
https://github.com/4QuantOSS/DashIntro/blob/master/notebooks/RawHTML.ipynb