Flask App Route + Hops

Hi, is there any update on this issue?

I require this functionality myself, and the fix @jfreund proposed does work.

I also ran into another issue when having a POST request that I would think is probably similar, but a similar fix doesn’t work.
I’m using Dash combined with Flask, and I have a callback function to navigate to other pages.
However, the callback request results in a POST request that goes into Hops, and in there it’s not able to find the hops component because the endpoint it’s looking for is /_dash-update-component, so it returns an error. So I tried a similar fix, by doing instead:

        elif method == "POST":
            data = request.data
            res, results = self.solve(uri=comp_uri, payload=data)
            if res:
                response = self._prep_response()
                response.data = results.encode(encoding="utf_8")
            else:
                response = self._prep_response(404, "Execution Error")
                return self.wsgi_app(environ, start_response)
            return response(environ, start_response)

However, when calling wsgi_app, it’s for some reason no longer able to load the request object, and it gets stuck trying to load it, as can also be seen here that it’s trying to fetch:

You can find the basics of my app below:

from flask import Flask
from flask_bootstrap import Bootstrap
import ghhops_server as hs
from dash import Dash, html, Output, Input, dcc
import dash_bootstrap_components as dbc

EXTERNAL_STYLESHEETS = [dbc.themes.BOOTSTRAP]
server = Flask(__name__)
app = Dash(
    server=server,
    url_base_pathname='/base/',
    external_stylesheets=EXTERNAL_STYLESHEETS)

hops = hs.Hops(server)
Bootstrap(server)

navbar = dbc.Navbar(
    dbc.Container(
        [
            html.A(
                dbc.Row(
                    [
                        # dbc.Col(html.Img(src=APP_LOGO, height='50px')),
                        dbc.Col(dbc.NavbarBrand('Polar Bear', className="ms-2"), style={'fontWeight': 'bold'})
                    ],
                    align='center'),
                href='/base/home/'),
            dbc.NavItem(dbc.NavLink("Training Data", href='/base/training_data/'))
        ]),
    color='dark',
    dark=True
)

app.layout = html.Div([
    dcc.Location(id='url', refresh=False),
    navbar,
    html.H1("Base page"),
    html.Div(id='page-content')
])

@app.callback(
    Output('page-content', 'children'),
    [Input('url', 'pathname')])
def display_page(pathname):
    if pathname == '/base/training_data/':
        return html.Div(children=[html.H1("Training data page")])
    else:
        return html.Div(children=[html.H1("Home page")])


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