pythonplotlycondaplotly-dashanaconda3

Plotly DASH output has no URL and unexpected behaviour


I have written a DASH app, but when I run it I dont get a url to the local host printed to my console, with the script staying open as long as the app is active. Instead, the script terminates and the final output to my console is:

starting app...
<IPython.lib.display.IFrame at 0x238562976a0>
In [19]: 

I would expect:

Dash is running on http://127.0.0.1:8050/

 * Serving Flask app 'app' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:8050 (Press CTRL+C to quit)

I am working in a conda environment, DASH/plotly/python versions are:

plotly                    5.16.1                   pypi_0    pypi
dash                      2.11.1                   pypi_0    pypi
dash-core-components      2.0.0                    pypi_0    pypi
dash-html-components      2.0.0                    pypi_0    pypi
dash-table                5.0.0                    pypi_0    pypi
python                    3.10.9               h966fe2a_2

DASH was imported via pip as suggested here, and plotly was bundled with DASH rather than explicitly installed by me - initially I installed both separately from conda forge, and this gave me the normal behaviour I would expect (URL printed to console etc), but the app itself was broken (so I remade my environment and got the issues described here). The app itself does seem to run when I navigate to my local host in my browser, but I suspect it will not update as the app seems to have stopped running in the console.

My app is:

import plotly.graph_objects as go
from dash import Dash, callback, html, dcc, dash_table, Input, Output, State, MATCH, ALL

app = Dash(__name__)

user_files = list(app_data.keys())

app.layout = html.Div([dcc.Tabs(id = 'user_tabs',
                       value = 'Single metric',
                       vertical = True,
                       children = [dcc.Tab(label = 'Single metric', 
                                   children=[html.Div([dcc.Dropdown(user_files, 
                                             user_files[0], 
                                             id='json_dropdown')
                                             ]),
                                             html.Div([dcc.Dropdown(id='record_dropdown')
                                                      ]),
                                             html.Div([dcc.Dropdown(id='bgc_dropdown')
                                                      ]),
                                             html.Div([dcc.Dropdown(['vis1', 
                                                                     'vis2', 
                                                                     'vis3', 
                                                                     'vis4'], 
                                                                    'vis1', 
                                                                    id='vis_dropdown')
                                                      ]),
                                             html.Div([dcc.Dropdown(mib_values, 
                                                       mib_values[0], 
                                                       id='mib_value')
                                                      ],id = 'mib_tab_style'),
                                             html.Div([dcc.Dropdown(operations, 
                                                       operations[0], 
                                                       id='mib_operation')
                                                       ],id = 'operation_tab_style'),
                                             html.Div([dcc.Graph(id='single_graph')],
                                                      style = {'width': '50%'}),
                                                 ])]
                               )])

if __name__ == '__main__':
    print ('launching app')
    app.run(debug = False)

Solution

  • Try to run your code,

    python your_app.py
    

    instead of running directly from Spyder.

    Some Spyder expert should shed more light on this,

    My assumption on this, is again not a Spyder expert, ideally Run file should run the above command, but assuming Spyder is a kind of ipykernel, it may not be executing your complete code as a main file instead of running it by importing your code? (not sure), you can check that by looking __name__ it may not be __main__!