Multi page app error

Hi guys! I am a newbie when it comes to multi-page apps in Dash and got stuck when I am trying to add a bit of complexity.

Created the pages following the code/structure in the documentation and everything works fine. The problem is that I don’t want to only return the app layout as in the basic example, but run some code in the that is written outside of the layout or callback (for example manipulating some data with pandas that is then used in the layout function).

I tried doing this using runpy :

@app.callback(Output('page-content', 'children'),
              [Input('url', 'pathname')])
def display_page(pathname):
    if pathname == '/countries/app1':
        runpy.run_module('countries.app1', run_name='__main__')
        return app1.layout
    elif pathname == '/countries/app2':
        return app2.layout
        return '404'

However, navigating to app1 prompts this error:

ValueError: signal only works in main thread

Any help would be much appreciated. Thanks.

Hi there,

I’m not 100% sure since you did not provide a MWE nor your full error trace, but it might be linked to this issue, which I just opened: (itself linked to a Flask issue, see the afore-mentioned link).