1

I am trying to get the first Dash example from https://dash.plotly.com/basic-callbacks running in a Jupyter Notebook with Jupyter Dash and the app runs fine as a standalone application, but errors out when implemented in the notebook and I can't figure this out. I get

TypeError: an integer is required (got type NoneType)

when I try to run the notebook.

from jupyter_dash import JupyterDash
import dash_html_components as html
import dash_core_components as dcc
import dash
from dash.dependencies import Input, Output

app = JupyterDash(__name__)

app.layout = html.Div([
    html.H6("Change the value in the text box to see callbacks in action!"),
    html.Div([
        "Input: ",
        dcc.Input(id='my-input', value='initial value', type='text')
    ]),
    html.Br(),
    html.Div(id='my-output'),

])


@app.callback(
    Output(component_id='my-output', component_property='children'),
    [Input(component_id='my-input', component_property='value')]
)
def update_output_div(input_value):
    return f'Output: {input_value}'


if __name__ == '__main__':
    app.run_server(mode="external")

The main difference is with the imports and app.run_server() In pycharm I just had from dash import Dash, html, dcc, Input, Output and app.run_server(debug=True). From what I've researched there's some issues with versioning and the updates I made should have fixed the issues and I can't seem to find anything about the error I am getting.

EDIT: Traceback from error

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp\1/ipykernel_31316/4067692673.py in <module>
     28 
     29 if __name__ == '__main__':
---> 30     app.run_server(mode="external")

~\AppData\Local\Programs\Python\Python39\lib\site-packages\jupyter_dash\jupyter_app.py in run_server(self, mode, width, height, inline_exceptions, **kwargs)
    220         self._terminate_server_for_port(host, port)
    221 
--> 222         # Configure pathname prefix
    223         requests_pathname_prefix = self.config.get('requests_pathname_prefix', None)
    224         if self._input_pathname_prefix is None:

~\AppData\Local\Programs\Python\Python39\lib\site-packages\jupyter_dash\_stoppable_thread.py in kill(self)

TypeError: an integer is required (got type NoneType)
wkl
  • 77,184
  • 16
  • 165
  • 176
Wallabee
  • 31
  • 4
  • Do you have a traceback that shows the line this is happening on? – wkl Aug 19 '22 at 19:29
  • @wkl Yep! I edited the original post. It seems like its an issue with the way its being run for some reason. – Wallabee Aug 22 '22 at 13:53
  • Are you using a similar Dash in another notebook? Try restarting the kernel and selecting Run all cells. On a separate point from the error, are the input values not placeholders? – r-beginners Aug 22 '22 at 14:23
  • @r-beginners I have no clue what the issue was, but I made a new environment and re-installed all the packages and now everything runs fine. Must've have been some version conflicts somewhere – Wallabee Aug 22 '22 at 18:28

1 Answers1

0

I had the same problem, and I found your question while trying to find a solution. Try adding host as string and port as integer types inside run_server like this: app.run_server(mode='external', host='your_host', port=your_port) My host is 127.0.0.1, and the port is 8050. Hope it helps

MkSash
  • 1