1

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)
Tim Kirkwood
  • 598
  • 2
  • 7
  • 18
  • thanks for your comment, do you mean just put it all on the same indent level? – Tim Kirkwood Aug 23 '23 at 05:52
  • 1
    sure, sorry about that - is the edited code better? – Tim Kirkwood Aug 23 '23 at 06:00
  • 1
    How are you running this code? Is it just `python your_app.py`? – shaik moeed Aug 23 '23 at 06:04
  • I'm running from within Spyder ("Run file" with the script open) - this is how I normally run my dash apps – Tim Kirkwood Aug 23 '23 at 06:07
  • 1
    Can you try as mentioned above? – shaik moeed Aug 23 '23 at 06:56
  • Interesting, it does seem to work when I do that - can you explain why? I've never had to run from the command line before. Some of the app interactivity isn't as expected but that might be a code issue, I'll have to go bug hunting before drawing conclusions. – Tim Kirkwood Aug 23 '23 at 07:06
  • Not a Spyder expert, ideally `Run file` should run the above command, but assuming Spyder is 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__`! – shaik moeed Aug 23 '23 at 07:15
  • hmm print (__name__) just above app.run() gives __main__ - very interesting! if you put your command line suggestion as an answer ill accept, cheers :) (double underscore is getting formatted to bold, not sure how to fix) – Tim Kirkwood Aug 23 '23 at 07:20
  • 1
    Wrap `__name__` with `\`` – shaik moeed Aug 23 '23 at 07:28
  • wouldn't that make it just a string comparison? if '__name__' == '__main__'? – Tim Kirkwood Aug 23 '23 at 08:57
  • Yes, that is a string comparison. Basically, `if __name__ == __main__`, is used to run the block of code only when that file got executed directly, instead, it won't get executed when the functions in this file get imported into others. More about it is [here](https://stackoverflow.com/q/419163/8353711) – shaik moeed Aug 23 '23 at 09:08

1 Answers1

0

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__!

shaik moeed
  • 5,300
  • 1
  • 18
  • 54