I am trying to embed a dash app within a Flask application. I followed this article Integrate Plotly Dash Into Your Flask App which worked great locally.
However, in production I am getting some errors (the page is loading, but the GET requests are referencing the wrong URL (which is likely the one before the server instance started). This is the error: GET https://dss-20eb47c0-dde60339-dku.eu-west-3.app.dataiku.io/dashapp/ 404 (Not Found)
The issue is that I have written a dash application with many dependencies (it’s using the assets folder, the pages folder and many more written modules) and it is not feasible to use the built-in dash webapp possibility (as the app is constructed by dataiku and does not allow to specify the assets or pages folder).
I’ve been trying to get this to work for at least 3 days (and 15 hours) but just cannot do it. Help would be massively appreciated. I’m open to other setups or structuring of this project.
This is my Flask backend (app is provided by dataiku → its a Flask instance):
import dataiku
import pandas as pd
from flask import request, Flask
from dash import Dash, dash, html
from datetime import datetime
server = app
dash_app = dash.Dash(server=server, routes_pathname_prefix="/dashapp/",)
dash_app.layout = html.Div("This is the dash app")
@server.route("/dashapp/")
def my(server):
return dash_app.index()
@server.route("/firstcall")
def index():
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return json.dumps({"status": "ok", "data": current_time})
const backendURL = dataiku.getWebAppBackendUrl("/firstcall");
window.onload = function() {
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", backendURL);
document.body.append(ifrm);
// Create a link to navigate to "/dashapp/"
var link = document.createElement("a");
link.href = "/dashapp/";
link.textContent = "Go to Dash App";
document.body.appendChild(link);
};
@Emil Do you have an idea perhaps? I’ve used your older dash_extensions solution but could not get it to run.